Data.Validation.Semiring
- Package
- validation
- Repository
- purescript/purescript-validation
This module defines a variant of applicative validation with
an Alt
instance, for validators which support errors
with multiple alternatives.
#V Source
newtype V err result
The V
functor, used for alternative validation
The Alternative
instance collects multiple failures in
an arbitrary Semiring
.
For example:
import Data.Semiring.Free
validate r :: Person -> V (Free Error) Person
validate person = { first: _, last: _, contact: _}
<$> validateName person.first
<*> validateName person.last
<*> (validateEmail person.contact <|> validatePhone person.contact)
Constructors
Instances
Newtype (V err result) _
(Eq err, Eq result) => Eq (V err result)
(Eq err) => Eq1 (V err)
(Ord err, Ord result) => Ord (V err result)
(Ord err) => Ord1 (V err)
(Show err, Show result) => Show (V err result)
Functor (V err)
Bifunctor V
(Semiring err) => Apply (V err)
(Semiring err) => Applicative (V err)
(Semiring err, Semigroup a) => Semigroup (V err a)
(Semiring err, Monoid a) => Monoid (V err a)
(Semiring err) => Alt (V err)
(Semiring err) => Plus (V err)
Foldable (V err)
Traversable (V err)
#validation Source
validation :: forall err result r. (err -> r) -> (result -> r) -> V err result -> r
Takes two functions an a V
value, if the validation failed the error is
applied to the first function, if the validation succeeded the inner value
is applied to the second function.
#andThen Source
andThen :: forall err a b. V err a -> (a -> V err b) -> V err b
Apply a function if successful, to enable chaining of validation.
Similar to a monadic bind, except it is inconsistent with Apply - that is,
where as apply (V err a) (V err a)
accumulates failures,
(V err a) ``andThen`` (\a -> V err a)
has fail-fast semantics
(>>=
would be expected to be consistent).