-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library for writing predicates and transformations over predicates in Haskell -- -- This package provides ways to write predicates such that they compose -- nicely and are easy to debug. @package predicate-transformers @version 0.17.0.0 -- | This library is based on the notion of a predicate transformer, the -- below type PT a b, which is a function from a to -- predicates on b. They act as a sort of compositional "matcher -- language". Composing these predicate transformers is meant to be -- analogous to composing optics and there are utilities for using -- predicate transformers with (lens-style) optics. -- -- Some predicate transformers provided by other libraries: all, -- any (base) either (base) allOf (lens) module PredicateTransformers -- | Class of possible predicate results. This is almost a lattice with -- or as disjunction, and as conjunction, fail as -- the falsy value, and succeed as the truthy value. However there -- may be multiple falsy values, and and will pick the first one -- it's passed, whereas or will pick the second it's passed. class Boolish a or :: Boolish a => a -> a -> a and :: Boolish a => a -> a -> a fail :: (Boolish a, HasCallStack) => Doc ann -> v -> a succeed :: Boolish a => a -- | Check and execute a callback on failure. assess :: Boolish a => a -> IO () -> a infixr 2 `or` infixr 3 `and` -- | The exception thrown by predicates of type `IO ()` by default. Other -- IOExceptions will work fine. data PredicateFailed PredicateFailed :: !CallStack -> Doc ann -> actual -> PredicateFailed -- | A convenient alias for predicates. type Pred p a = a -> p -- | Predicate transformers form a category where composition is ordinary -- function composition. Forms a category with . and id. -- Multiple are already provided by the standard library, for instance -- all and any. type PT p a b = Pred p a -> Pred p b -- | Operate on the last value in a foldable, or fail if it's not present. endingWith :: (HasCallStack, Boolish p, Foldable f) => PT p a (f a) -- | Operate on the first value in a foldable, or fail if it's not present. startingWith :: (HasCallStack, Boolish p, Foldable f) => PT p a (f a) -- | Require that a Prism matches, and apply the predicate to its -- contents. This works for folds, too. match :: (HasCallStack, Boolish p) => Getting [a] s a -> PT p a s -- | Only test the kth element of a foldable. kth :: (Boolish p, Foldable f) => Int -> PT p a (f a) -- | Given a list of predicates and a list of values, ensure that each -- predicate holds for each respective value. Fails if the two lists have -- different lengths. list :: (HasCallStack, Boolish p) => [Pred p a] -> [a] -> p -- | Given a functor-full of predicates, and a functor-full of values, -- ensure that the structures of the two functors match and apply all of -- the predicates to all of the values. Generalized version of -- list. predful :: (HasCallStack, Boolish p, Eq (f ()), Functor f, Foldable f) => f (Pred p a) -> Pred p (f a) -- | Given a representable functor-full of predicates, and a functor-full -- of values, yield a representable functor-full of booleans. Similar to -- predful. compose :: Representable f => f (Pred p a) -> f a -> f p -- | Test all predicates against one value. allTrue :: (Boolish p, Foldable f) => f (Pred p a) -> Pred p a -- | Check that a predicate is true for all values behind a generalized -- getter and that there's at least one value for which it's true. allOf1 :: (HasCallStack, Boolish p) => Getting [a] s a -> PT p a s -- | Sugar for tupling. pattern (:=>) :: a -> b -> (a, b) -- | A pair of predicates, made into a predicate on pairs. pair :: Boolish p => Pred p a -> Pred p b -> Pred p (a, b) -- | Flipped function composition; pf f for a function f -- is a predicate transformer such that pf f p i == p (f i). fun :: (a -> b) -> PT p b a -- | Higher precedence $, to work well with &. (?) :: (a -> b) -> a -> b infixr 8 ? -- | Prints the input of a predicate, for debugging. traced :: Show a => (a -> String) -> PT c a a -- | Prints the input of a predicate, for debugging. tracedShow :: Show a => PT c a a -- | Prints the input of a predicate, if the predicate fails, using -- Show. Requires that the predicate's output type can be checked -- for failure. traceFailShow :: (Boolish p, Show a) => PT p a a -- | Prints the input of a predicate over functions, if the predicate -- fails. Requires that the predicate's output type can be checked for -- failure. traceFail :: Boolish p => (a -> String) -> PT p a a -- | Predicate which triggers full evaluation of its input and succeeds. -- Useful for testing that an exception isn't thrown. forced :: (Boolish p, NFData a) => Pred p a -- | Predicate on equality. equals :: (HasCallStack, Boolish p, Eq a) => a -> Pred p a instance PredicateTransformers.Boolish GHC.Types.Bool instance PredicateTransformers.Boolish a => PredicateTransformers.Boolish (e -> a) instance (a GHC.Types.~ ()) => PredicateTransformers.Boolish (GHC.Types.IO a) instance GHC.Exception.Type.Exception PredicateTransformers.PredicateFailed instance GHC.Show.Show PredicateTransformers.PredicateFailed