Evaluates the specified block, catching exceptions of the specified type and returning them on the invalid side of
the resulting Validated
.
Evaluates the specified block, catching exceptions of the specified type and returning them on the invalid side of
the resulting Validated
. Uncaught exceptions are propagated.
For example:
scala> Validated.catchOnly[NumberFormatException] { "foo".toInt } res0: Validated[NumberFormatException, Int] = Invalid(java.lang.NumberFormatException: For input string: "foo")
This method and its usage of NotNull are inspired by and derived from
the fromTryCatchThrowable
method contributed
to Scalaz by Brian McKenna.
If the condition is satisfied, return the given A
as valid,
otherwise return the given E
as invalid.
If the condition is satisfied, return the given A
as valid,
otherwise return the given E
as invalid.
If the condition is satisfied, return the given B
as valid NEC,
otherwise return the given A
as invalid NEC.
If the condition is satisfied, return the given B
as valid NEC,
otherwise return the given A
as invalid NEC.
If the condition is satisfied, return the given A
as valid NEL,
otherwise return the given E
as invalid NEL.
If the condition is satisfied, return the given A
as valid NEL,
otherwise return the given E
as invalid NEL.
Converts an Either[A, B]
to a Validated[A, B]
.
Converts an Either[A, B]
to a Validated[A, B]
.
Converts an Ior[A, B]
to a Validated[A, B]
.
Converts an Ior[A, B]
to a Validated[A, B]
.
Converts an Option[B]
to a Validated[A, B]
, where the provided ifNone
values is returned on
the invalid of the Validated
when the specified Option
is None
.
Converts an Option[B]
to a Validated[A, B]
, where the provided ifNone
values is returned on
the invalid of the Validated
when the specified Option
is None
.
Converts a Try[A]
to a Validated[Throwable, A]
.
Converts a Try[A]
to a Validated[Throwable, A]
.
Converts an E
to a Validated[E, A]
.
Converts an E
to a Validated[E, A]
.
For example:
scala> Validated.invalid[IllegalArgumentException, String](new IllegalArgumentException("Argument is nonzero")) res0: Validated[IllegalArgumentException, String] = Invalid(java.lang.IllegalArgumentException: Argument is nonzero)
Converts an A
to a ValidatedNec[A, B]
.
Converts an A
to a ValidatedNec[A, B]
.
For example:
scala> Validated.invalidNec[IllegalArgumentException, String](new IllegalArgumentException("Argument is nonzero")) res0: ValidatedNec[IllegalArgumentException, String] = Invalid(Chain(java.lang.IllegalArgumentException: Argument is nonzero))
Converts an E
to a ValidatedNel[E, A]
.
Converts an E
to a ValidatedNel[E, A]
.
For example:
scala> Validated.invalidNel[IllegalArgumentException, String](new IllegalArgumentException("Argument is nonzero")) res0: ValidatedNel[IllegalArgumentException, String] = Invalid(NonEmptyList(java.lang.IllegalArgumentException: Argument is nonzero))
Converts a A
to a Validated[E, A]
.
Converts a A
to a Validated[E, A]
.
For example:
scala> Validated.valid[IllegalArgumentException, String]("Hello world") res0: Validated[IllegalArgumentException, String] = Valid(Hello world)
Converts a B
to a ValidatedNec[A, B]
.
Converts a B
to a ValidatedNec[A, B]
.
For example:
scala> Validated.validNec[IllegalArgumentException, String]("Hello world") res0: ValidatedNec[IllegalArgumentException, String] = Valid(Hello world)
Converts a A
to a ValidatedNel[E, A]
.
Converts a A
to a ValidatedNel[E, A]
.
For example:
scala> Validated.validNel[IllegalArgumentException, String]("Hello world") res0: ValidatedNel[IllegalArgumentException, String] = Valid(Hello world)