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.2.2@sha256:858e85eecdd2ceb14f452dc3bb4db1d837156295563e8059f884b17a04b209a3,4924

Module documentation for 1.2.2

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, and corresponding classes for Failure and Success) following the conventions of makeClassy and makeClassyPrisms from lens.

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

  • Isomorphisms to Either and (Bool, a).

Validator

The Validator newtype is a profunctor transformer:

newtype Validator e p x a = Validator (p x (Validation e a))

Validator e (->) x a is isomorphic to x -> Validation e a. The profunctor parameter p generalises this to other optic-like contexts such as Tagged, Iso, and Prism.

Instances include Functor, Apply, Applicative, Alt, Selective, Profunctor, Strong, Choice, Semigroupoid, Category, Arrow, ArrowApply, ArrowChoice, and Wrapped.

The Applicative instance accumulates errors in parallel (using Semigroup), while Category composition short-circuits on Failure (like monadic bind).

The library also provides profunctor newtype wrappers (Iso'', Prism'') that allow Validator to be parameterised over monomorphic isos and prisms.