Data.Validation.Semigroup
- Package
- validation
- Repository
- purescript/purescript-validation
This module defines an applicative functor for applicative validation.
Applicative validation differs from monadic validation using Either in
that it allows us to collect multiple errors using a Semigroup, whereas
Either terminates on the first error.
#V Source
newtype V err resultThe V functor, used for applicative validation
The Applicative instance collects multiple failures in
an arbitrary Semigroup.
For example:
validate :: Person -> V (Array Error) Person
validate person = { first: _, last: _, email: _ }
<$> validateName person.first
<*> validateName person.last
<*> validateEmail person.email
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(Semigroup err) => Apply (V err)(Semigroup err) => Applicative (V err)(Semigroup err, Semigroup a) => Semigroup (V err a)(Semigroup err, Monoid a) => Monoid (V err a)Foldable (V err)Traversable (V err)
#andThen Source
andThen :: forall b a err. V err a -> (a -> V err b) -> V err bApply 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 accumulates failures: apply (invalid x) (invalid y) = invalid (x <> y),
andThen has fail-fast semantics: andThen (invalid x) (\_ -> invalid y) = invalid x
(>>= would be expected to be consistent).