Apply a function (that returns a Validated
) in the valid case.
Apply a function (that returns a Validated
) in the valid case.
Otherwise return the original Validated
.
This allows "chained" validation: the output of one validation can be fed into another validation function.
This function is similar to flatMap
on Either
. It's not called flatMap
,
because by Cats convention, flatMap
is a monadic bind that is consistent
with ap
. This method is not consistent with ap (or other
Apply
-based methods), because it has "fail-fast" behavior as opposed to
accumulating validation failures.
From Apply: if both the function and this value are Valid, apply the function
From Apply: if both the function and this value are Valid, apply the function
Validated is a functor.Bifunctor, this method applies one of the given functions.
Validated is a functor.Bifunctor, this method applies one of the given functions.
Combine this Validated
with another Validated
, using the Semigroup
instances of the underlying E
and A
instances.
Combine this Validated
with another Validated
, using the Semigroup
instances of the underlying E
and A
instances. The resultant Validated
will be Valid
, if, and only if, both this Validated
instance and the
supplied Validated
instance are also Valid
.
Ensure that a successful result passes the given predicate,
falling back to an Invalid of onFailure
if the predicate
returns false.
Ensure that a successful result passes the given predicate,
falling back to an Invalid of onFailure
if the predicate
returns false.
For example:
scala> Validated.valid("").ensure(new IllegalArgumentException("Must not be empty"))(_.nonEmpty) res0: Validated[IllegalArgumentException, String] = Invalid(java.lang.IllegalArgumentException: Must not be empty)
Is this Valid and matching the given predicate
Is this Valid and matching the given predicate
apply the given function to the value with the given B when valid, otherwise return the given B
apply the given function to the value with the given B when valid, otherwise return the given B
Lazily-apply the given function to the value with the given B when valid, otherwise return the given B.
Lazily-apply the given function to the value with the given B when valid, otherwise return the given B.
Is this Invalid or matching the predicate
Is this Invalid or matching the predicate
Run the side-effecting function on the value if it is Valid
Run the side-effecting function on the value if it is Valid
Return the Valid value, or the default if Invalid
Return the Valid value, or the default if Invalid
Apply a function to an Invalid value, returning a new Invalid value.
Apply a function to an Invalid value, returning a new Invalid value. Or, if the original valid was Valid, return it.
Apply a function to a Valid value, returning a new Valid value
Apply a function to a Valid value, returning a new Valid value
Return this if it is Valid, or else fall back to the given default.
Return this if it is Valid, or else fall back to the given default.
From Product
From Product
Converts the value to an Either[E, A]
Converts the value to an Either[E, A]
Convert this value to a single element List if it is Valid, otherwise return an empty List
Convert this value to a single element List if it is Valid, otherwise return an empty List
Returns Valid values wrapped in Some, and None for Invalid values
Returns Valid values wrapped in Some, and None for Invalid values
Lift the Invalid value into a NonEmptyList.
Lift the Invalid value into a NonEmptyList.
When Valid, apply the function, marking the result as valid inside the Applicative's context, when Invalid, lift the Error into the Applicative's context
When Valid, apply the function, marking the result as valid inside the Applicative's context, when Invalid, lift the Error into the Applicative's context
Return the Valid value, or the result of f if Invalid
Return the Valid value, or the result of f if Invalid
Convert to an Either, apply a function, convert back.
Convert to an Either, apply a function, convert back. This is handy when you want to use the Monadic properties of the Either type.