-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Composable validations for your Haskell data types -- -- Composable validations for your Haskell data types. @package validators @version 0.0.1 -- | This module defines the Validation data type. -- -- Most functionality is the same as in the validation library, -- but the module doesn't provide certain typeclass instances that -- require a dependency on the lens library. module Data.Validation -- | A Validation is very similar to Either in that it -- contains a value of type e or a. In contrast to Either -- however, Validation accumulates all errors it comes across in it's -- Applicative instance. -- -- A complete example where Validation is used can be found here. data Validation err a Failure :: !err -> Validation err a Success :: !a -> Validation err a -- | Conversion function from Validation to Either. -- --
--   >>> toEither (Failure 1)
--   Left 1
--   
--   >>> toEither (Success True)
--   Right True
--   
toEither :: Validation err a -> Either err a -- | Conversion function from Either to Validation. -- --
--   >>> fromEither (Left 1)
--   Failure 1
--   
--   >>> fromEither (Right True)
--   Success True
--   
fromEither :: Either err a -> Validation err a instance (GHC.Classes.Ord err, GHC.Classes.Ord a) => GHC.Classes.Ord (Data.Validation.Validation err a) instance (GHC.Show.Show err, GHC.Show.Show a) => GHC.Show.Show (Data.Validation.Validation err a) instance (GHC.Classes.Eq err, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Validation.Validation err a) instance GHC.Base.Functor (Data.Validation.Validation err) instance Data.Bifunctor.Bifunctor Data.Validation.Validation instance Data.Foldable.Foldable (Data.Validation.Validation err) instance Data.Bifoldable.Bifoldable Data.Validation.Validation instance Data.Traversable.Traversable (Data.Validation.Validation err) instance Data.Bitraversable.Bitraversable Data.Validation.Validation instance GHC.Base.Semigroup err => GHC.Base.Applicative (Data.Validation.Validation err) -- | This module defines the Validator data type and helper -- functions for creating various validators. module Data.Validator -- | Datatype for checking if a validation holds for a subject. -- -- -- -- Execute a validator by passing it to the validate function. -- -- A Validator is both a Semigroup and a Monoid, making it -- possible to combine smaller validators into larger validators. A -- combined validator will accumulate errors from all of it's -- sub-validators. data Validator err subject -- | Runs a validator on a subject. -- -- The result is a Validation containing all accumulated errors, -- or the subject wrapped in a Success value. validate :: Validator err subject -> subject -> Validation err subject -- | Creates a validator that will return an error if the given predicate -- doesn't hold. -- -- Since any predicate can be provided for checking if the subject -- satisfies certain conditions, this can be used to build your own -- custom validators. -- -- Usage: -- --
--   >>> let validator = assert (> 10) ["too small"]
--   
--   >>> validate validator 11
--   Success 11
--   
-- --
--   >>> validate validator 1
--   Failure ["too small"]
--   
assert :: (subject -> Bool) -> err -> Validator err subject -- | Creates a validator that will return an error if the given predicate -- holds. -- -- Since any predicate can be provided for checking if the subject -- satisfies certain conditions, this can be used to build your own -- custom validators. -- -- Usage: -- --
--   >>> let validator = refute (> 10) ["too big"]
--   
--   >>> validate validator 11
--   Failure ["too big"]
--   
-- --
--   >>> validate validator 1
--   Success 1
--   
refute :: (subject -> Bool) -> err -> Validator err subject -- | Returns an error if a Maybe is Nothing. -- -- Usage: -- --
--   >>> let validator = ifNothing ["Found nothing."]
--   
--   >>> validate validator Nothing
--   Failure ["Found nothing."]
--   
-- --
--   >>> validate validator (Just "Bob")
--   Success (Just "Bob")
--   
ifNothing :: err -> Validator err (Maybe a) -- | Returns an error if an Either contains a Left. -- -- Usage: -- --
--   >>> let validator = ifLeft ["Found left."]
--   
--   >>> validate validator (Left 123)
--   Failure ["Found left."]
--   
-- --
--   >>> validate validator (Right 456)
--   Success (Right 456)
--   
ifLeft :: err -> Validator err (Either a b) -- | Helper typeclass for checking if a value is empty. class HasSize a size :: HasSize a => a -> Int isEmpty :: HasSize a => a -> Bool -- | Returns an error if the function returns an "empty" value. -- -- Usage: -- --
--   >>> let validator = ifEmpty ["Empty."]
--   
--   >>> validate validator []
--   Failure ["Empty."]
--   
-- --
--   >>> validate validator [1, 2, 3]
--   Success [1,2,3]
--   
--   >>> validate validator (Map.fromList [('a', 1), ('b', 2)])
--   Success (fromList [('a',1),('b',2)])
--   
ifEmpty :: HasSize subject => err -> Validator err subject -- | Returns an error if the value has a size smaller than required. -- -- Usage: -- --
--   >>> let validator = minSize 3 ["Too small."]
--   
--   >>> validate validator []
--   Failure ["Too small."]
--   
--   >>> validate validator [1, 2]
--   Failure ["Too small."]
--   
-- --
--   >>> validate validator [1, 2, 3]
--   Success [1,2,3]
--   
minSize :: HasSize subject => Int -> err -> Validator err subject -- | Returns an error if the value has a size smaller than required. -- -- Usage: -- --
--   >>> let validator = maxSize 3 ["Too big."]
--   
--   >>> validate validator [1, 2, 3, 4]
--   Failure ["Too big."]
--   
-- --
--   >>> validate validator [1, 2, 3]
--   Success [1,2,3]
--   
maxSize :: HasSize subject => Int -> err -> Validator err subject -- | Helper typeclass for checking if a value contains only whitespace -- characters. class IsOnlyWhiteSpace a isOnlyWhiteSpace :: IsOnlyWhiteSpace a => a -> Bool -- | Returns an error if the function returns a value containing only -- whitespace. -- -- Usage: -- --
--   >>> let validator = ifBlank ["Only whitespace."]
--   
--   >>> validate validator "   \t \n \r "
--   Failure ["Only whitespace."]
--   
-- --
--   >>> validate validator "not empty"
--   Success "not empty"
--   
ifBlank :: IsOnlyWhiteSpace subject => err -> Validator err subject instance GHC.Show.Show err => GHC.Show.Show (Data.Validator.Result err) instance GHC.Classes.Eq err => GHC.Classes.Eq (Data.Validator.Result err) instance Data.Validator.IsOnlyWhiteSpace GHC.Base.String instance Data.Validator.IsOnlyWhiteSpace Data.Text.Internal.Lazy.Text instance Data.Validator.IsOnlyWhiteSpace Data.Text.Internal.Text instance Data.Validator.HasSize [a] instance Data.Validator.HasSize (Data.Map.Internal.Map k v) instance Data.Validator.HasSize (Data.Set.Internal.Set a) instance Data.Validator.HasSize (Data.Sequence.Internal.Seq a) instance GHC.Base.Semigroup err => GHC.Base.Semigroup (Data.Validator.Validator err subject) instance GHC.Base.Monoid err => GHC.Base.Monoid (Data.Validator.Validator err subject) instance Data.Functor.Contravariant.Contravariant (Data.Validator.Validator err) instance GHC.Base.Semigroup err => GHC.Base.Semigroup (Data.Validator.Result err) instance GHC.Base.Monoid err => GHC.Base.Monoid (Data.Validator.Result err)