BSD-3-Clause licensed and maintained by Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>
This version can be pinned in stack with:validation-1.3.0@sha256:0cf1f126f9708a78542516fdf4539e96736e19f7bb148b71bb891d9a924675fa,4805

A data type like Either but with an accumulating Applicative instance.

Validation

The Validation data type is isomorphic to Either, but has an instance of Applicative that accumulates on the error side. That is to say, if two (or more) errors are encountered, they are appended using a Semigroup operation.

As a consequence of this Applicative instance, there is no corresponding Bind or Monad instance. Validation is an example of, "An applicative functor that is not a monad."

The library provides:

  • Classy optics (GetValidation, HasValidation, ReviewValidation, AsValidation) following the conventions of makeClassy and makeClassyPrisms from lens.

  • Polymorphic prisms (__Failure, __Success) for type-changing operations.

  • Isomorphisms to Either and (Bool, a).

ValidationMonadT

ValidationMonadT err m a is a monad transformer wrapping m (Validation err a). Unlike Validation, it has short-circuiting Applicative, Bind, Monad, and MonadError instances.

Validators

Four validator newtypes wrap a validation function with different type parameter orders, enabling different class instances:

  • Validator x err aBifunctor, accumulating Applicative

  • ValidatorProfunctor err x aProfunctor, accumulating Applicative

  • ValidatorMonadT x err f aMonad, MonadTrans, BindTrans

  • ValidatorMonadProfunctorT err f x aProfunctor, Monad, Category, Arrow

All four are isomorphic and have cross-type optics instances.