Module

Data.Validation.Semigroup

Package
purescript-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

data V err result

The 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

Instances

#unV Source

unV :: forall r result err. (err -> r) -> (result -> r) -> V err result -> r

Unpack the V type constructor, providing functions to handle the error and success cases.

#invalid Source

invalid :: forall result err. err -> V err result

Fail with a validation error

#isValid Source

isValid :: forall result err. V err result -> Boolean

Test whether validation was successful or not