The Validation(a, b)
applicative functor.
+ type: Validation(a, b) <: Applicative, Functor, Show, Eq
Constructs a new Validation(a, b)
applicative holding a Failure
value.
Constructs a new Validation(a, b)
applicative holding a Success
value.
Constructs a new Validation(a, b)
from a nullable type. Takes the
Failure
case if the value is null
or undefined
. Takes the
Success
case otherwise.
+ type: a -> Validation(a, a)
True if the Validation(a, b)
contains a Failure
value.
+ type: Boolean
True if the Validation(a, b)
contains a Success
value.
+ type: Boolean
Creates a new Validation(a, b)
instance holding the Success
value b
.
b
can be any value, including null
, undefined
or another
Validation(a, b)
applicative.
If both applicatives represent a Success
value, maps the value in
the given validation with the function in this validation. Otherwise
aggregates the errors with a semigroup — both Failures must hold a
semigroup.
Transforms the Success
value of the Validation(a, b)
applicative using
a regular unary function.
Returns a textual representation of the Validation(a, c)
applicative.
Tests if an Validation(a, b)
applicative is equal to another
Validation(a, b)
applicative.
+ type: (@Validation(a, b)) => Validation(a, b) -> Boolean
Extracts the Success
value out of the Validation(a, b)
applicative, if
it exists. Otherwise throws a TypeError
.
Success
value.Extracts the Success
value out of the Validation(a, b)
applicative. If
the applicative doesn't have a Success
value, returns the given default.
+ type: (@Validation(a, b)) => b -> b
Transforms a Failure
value into a new Validation(a, b)
applicative. Does nothing if the applicative contains a Success
value.
+ type: (@Validation(a, b)) => (a -> Validation(c, b)) -> Validation(c, b)
Returns the value of whichever side of the disjunction that is present. + type: (@Validation(a, a)) => Unit -> a
Catamorphism. Takes two functions, applies the leftmost one to the
Failure
value and the rightmost one to the Success
value,
depending on which one is present.
+ type: (@Validation(a, b)) => (a -> c) -> (b -> c) -> c
Swaps the disjunction values.
Maps both sides of the disjunction. + type: (@Validation(a, b)) => (a -> c) -> (b -> d) -> Validation(c, d)
Maps the left side of the disjunction.
Represents the Success
side of the disjunction.
Represents the Failure
side of the disjunction.
Applicative: Validation
The
Validation(a, b)
is a disjunction that's more appropriate for validating inputs, or any use case where you want to aggregate failures. Not only theValidation
provides a better terminology for working with such cases (Failure
andSuccess
versusLeft
andRight
), it also allows one to easily aggregate failures and successes as an Applicative Functor.