Module

Data.Validation.Semiring

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

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.

#toEither Source

toEither :: forall result err. V err result -> Either err result