-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A data-type like Either but with an accumulating Applicative -- -- -- A data-type like Either but with differing properties and type-class -- instances. -- -- Library support is provided for this different representation, include -- lens-related functions for converting between each and -- abstracting over their similarities. -- -- -- -- The AccValidation 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. -- AccValidation is an example of, "An applicative functor that is -- not a monad." @package validation @version 0.6.3 -- | A data type similar to Data.Either that accumulates failures. module Data.Validation -- | An AccValidation is either a value of the type err -- or a, similar to Either. However, the -- Applicative instance for AccValidation -- accumulates errors using a Semigroup on err. In -- contrast, the Applicative for Either returns only -- the first error. -- -- A consequence of this is that AccValidation has no -- Bind or Monad instance. This is because such an instance -- would violate the law that a Monad's ap must equal the -- Applicative's <*> -- -- An example of typical usage can be found here. data AccValidation err a AccFailure :: err -> AccValidation err a AccSuccess :: a -> AccValidation err a -- | validates the a with the given predicate, returning -- e if the predicate does not hold. -- -- This can be thought of as having the less general type: -- --
--   validate :: e -> (a -> Bool) -> a -> AccValidation e a
--   
validate :: Validate v => e -> (a -> Bool) -> a -> v e a -- | validationNel is liftError specialised to -- NonEmpty lists, since they are a common semigroup to use. validationNel :: Either e a -> AccValidation (NonEmpty e) a -- | Converts from Either to AccValidation. fromEither :: Either e a -> AccValidation e a -- | liftError is useful for converting an Either to an -- AccValidation when the Left of the Either needs -- to be lifted into a Semigroup. liftError :: (b -> e) -> Either b a -> AccValidation e a -- | validation is the catamorphism for AccValidation. validation :: (e -> c) -> (a -> c) -> AccValidation e a -> c -- | Converts from AccValidation to Either. toEither :: AccValidation e a -> Either e a -- | v orElse a returns a when v is -- AccFailure, and the a in AccSuccess a. -- -- This can be thought of as having the less general type: -- --
--   orElse :: AccValidation e a -> a -> a
--   
orElse :: Validate v => v e a -> a -> a -- | Return the a or run the given function over the e. -- -- This can be thought of as having the less general type: -- --
--   valueOr :: (e -> a) -> AccValidation e a -> a
--   
valueOr :: Validate v => (e -> a) -> v e a -> a -- | ensure leaves the validation unchanged when the predicate -- holds, or fails with e otherwise. -- -- This can be thought of as having the less general type: -- --
--   ensure :: e -> (a -> Bool) -> AccValidation e a -> AccValidation e a
--   
ensure :: Validate v => e -> (a -> Bool) -> v e a -> v e a -- | codiagonal gets the value out of either side. codiagonal :: AccValidation a a -> a -- | Run a function on anything with a Validate instance (usually Either) -- as if it were a function on AccValidation -- -- This can be thought of as having the type -- --
--   (Either e a -> Either e' a') -> AccValidation e a -> AccValidation e' a'
--   
validationed :: Validate v => (v e a -> v e' a') -> AccValidation e a -> AccValidation e' a' -- | bindValidation binds through an AccValidation, which is -- useful for composing AccValidations sequentially. Note that despite -- having a bind function of the correct type, AccValidation is not a -- monad. The reason is, this bind does not accumulate errors, so it does -- not agree with the Applicative instance. -- -- There is nothing wrong with using this function, it just does not make -- a valid Monad instance. bindValidation :: AccValidation e a -> (a -> AccValidation e b) -> AccValidation e b -- | This prism generalises _Left. It targets the failure case of -- either Either or AccValidation. _Failure :: Validate f => Prism (f e1 a) (f e2 a) e1 e2 -- | This prism generalises _Right. It targets the success case of -- either Either or AccValidation. _Success :: Validate f => Prism (f e a) (f e b) a b -- | The Validate class carries around witnesses that the type -- f is isomorphic to AccValidation, and hence isomorphic to -- Either. class Validate f _AccValidation :: Validate f => Iso (f e a) (f g b) (AccValidation e a) (AccValidation g b) _Either :: Validate f => Iso (f e a) (f g b) (Either e a) (Either g b) -- | revalidate converts between any two instances of -- Validate. revalidate :: (Validate f, Validate g) => Iso (f e1 s) (f e2 t) (g e1 s) (g e2 t) instance GHC.Generics.Generic (Data.Validation.AccValidation err a) instance (Data.Data.Data a, Data.Data.Data err) => Data.Data.Data (Data.Validation.AccValidation err a) instance (GHC.Show.Show a, GHC.Show.Show err) => GHC.Show.Show (Data.Validation.AccValidation err a) instance (GHC.Classes.Ord a, GHC.Classes.Ord err) => GHC.Classes.Ord (Data.Validation.AccValidation err a) instance (GHC.Classes.Eq a, GHC.Classes.Eq err) => GHC.Classes.Eq (Data.Validation.AccValidation err a) instance Data.Validation.Validate Data.Validation.AccValidation instance Data.Validation.Validate Data.Either.Either instance GHC.Base.Functor (Data.Validation.AccValidation err) instance Data.Semigroup.Semigroup err => Data.Functor.Bind.Class.Apply (Data.Validation.AccValidation err) instance Data.Semigroup.Semigroup err => GHC.Base.Applicative (Data.Validation.AccValidation err) instance Data.Functor.Alt.Alt (Data.Validation.AccValidation err) instance Data.Foldable.Foldable (Data.Validation.AccValidation err) instance Data.Traversable.Traversable (Data.Validation.AccValidation err) instance Data.Bifunctor.Bifunctor Data.Validation.AccValidation instance Data.Bifoldable.Bifoldable Data.Validation.AccValidation instance Data.Bitraversable.Bitraversable Data.Validation.AccValidation instance Data.Semigroup.Semigroup e => Data.Semigroup.Semigroup (Data.Validation.AccValidation e a) instance GHC.Base.Monoid e => GHC.Base.Monoid (Data.Validation.AccValidation e a) instance Control.Lens.Iso.Swapped Data.Validation.AccValidation instance (Control.DeepSeq.NFData e, Control.DeepSeq.NFData a) => Control.DeepSeq.NFData (Data.Validation.AccValidation e a)