new Validation()
Validation[α, β] <: Applicative[β] , Functor[β] , Show , Eq
The Validation[α, β]
is a disjunction that's more appropriate for
validating inputs, or any use case where you want to aggregate failures. Not
only does the Validation
provide a better terminology for working with
such cases (Failure
and Success
versus Failure
and Success
), it also
allows one to easily aggregate failures and successes as an Applicative
Functor.
- Source:
Members
-
isFailure
Boolean
-
True if the
Validation[α, β]
contains aFailure
value.- Source:
-
isSuccess
Boolean
-
True if the
Validation[α, β]
contains aSuccess
value.- Source:
Methods
-
<static> Failure()
a → Validation[α, β]
-
Constructs a new
Validation[α, β]
structure holding aFailure
value.- Source:
-
<static> fromEither()
Either[α, β] → Validation[α, β]
-
Constructs a new
Either[α, β]
structure from aValidation[α, β]
type.- Source:
-
<static> fromNullable()
α → Validation[α, α]
-
Constructs a new
Validation[α, β]
structure from a nullable type.Takes the
Failure
case if the value isnull
orundefined
. Takes theSuccess
case otherwise.- Source:
-
<static> of()
β → Validation[α, β]
-
Creates a new
Validation[α, β]
instance holding theSuccess
valueb
.b
can be any value, includingnull
,undefined
or anotherValidation[α, β]
structure.- Source:
-
<static> Success()
β → Validation[α, β]
-
Constructs a new
Etiher[α, β]
structure holding aSuccess
value.- Source:
-
ap()
(@Validation[α, β → γ], f:Applicative[_]) => f[β] → f[γ]
-
Applies the function inside the
Success
case of theValidation[α, β]
structure to another applicative type.The
Validation[α, β]
should contain a function value, otherwise aTypeError
is thrown.- Source:
-
bimap()
(@Validation[α, β]) => (α → γ), (β → δ) → Validation[γ, δ]
-
Maps both sides of the disjunction.
- Source:
-
failureMap()
(@Validation[α, β]) => (α → γ) → Validation[γ, β]
-
Maps the failure side of the disjunction.
- Source:
-
fold()
(@Validation[α, β]) => (α → γ), (β → γ) → γ
-
Applies a function to each case in this data structure.
- Source:
-
get()
(@Validation[α, β]) => Void → β :: partial, throws
-
Extracts the
Success
value out of theValidation[α, β]
structure, if it exists. Otherwise throws aTypeError
.- Source:
- See:
-
- module:lib/validation~Validation#getOrElse — A getter that can handle failures.
- module:lib/validation~Validation#merge — The convergence of both values.
Throws:
-
if the structure has no `Success` value.
- Type
- TypeError
-
getOrElse()
(@Validation[α, β]) => β → β
-
Extracts the
Success
value out of theValidation[α, β]
structure. If the structure doesn't have aSuccess
value, returns the given default.- Source:
-
isEqual()
(@Validation[α, β]) => Validation[α, β] → Boolean
-
Tests if an
Validation[α, β]
structure is equal to anotherValidation[α, β]
structure.- Source:
-
leftMap()
(@Validation[α, β]) => (α → γ) → Validation[γ, β]
-
Maps the failure side of the disjunction.
- Deprecated:
- in favour of module:lib/validation~Validation#failureMap
- Source:
-
map()
(@Validation[α, β]) => (β → γ) → Validation[α, γ]
-
Transforms the
Success
value of theValidation[α, β]
structure using a regular unary function.- Source:
-
merge()
(@Validation[α, α]) => Void → α
-
Returns the value of whichever side of the disjunction that is present.
- Source:
-
orElse()
(@Validation[α, β]) => (α → Validation[γ, β]) → Validation[γ, β]
-
Transforms a
Failure
value into a newValidation[α, β]
structure. Does nothing if the structure contain aSuccess
value.- Source:
-
swap()
(@Validation[α, β]) => Void → Validation[β, α]
-
Swaps the disjunction values.
- Source:
-
toString()
(@Validation[α, β]) => Void → String
-
Returns a textual representation of the
Validation[α, β]
structure.- Source: