-- 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.12.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 mostly a lattice with
-- otherHand as disjunction, also as conjunction,
-- stop as the falsy value, and continue as the truthy
-- value. There may be multiple falsy values, however. Note that test
-- failure messages are not really the domain of this library. It's the
-- author's hope that they can be mostly replaced by traceFail.
class Predicatory a
otherHand :: Predicatory a => a -> a -> a
also :: Predicatory a => a -> a -> a
stop :: Predicatory a => a
continue :: Predicatory a => a
infixr 2 `otherHand`
infixr 3 `also`
-- | Class of predicate results which can be checked for failure, by
-- triggering an action.
class Exceptional a
assess :: Exceptional a => a -> IO () -> a
-- | The exception thrown by predicates of type `IO ()` by default. Other
-- IOExceptions will work fine.
data PredicateFailed
PredicateFailed :: PredicateFailed
-- | A convenient alias for predicates.
type Pred a = a -> Bool
-- | 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 = (a -> p) -> (b -> p)
-- | Operate on the Just branch of a Maybe, or fail.
just :: Predicatory p => PT p a (Maybe a)
-- | Operate on the Left branch of an Either, or fail.
left :: Predicatory p => PT p e (Either e a)
-- | Operate on the Right branch of an Either, or fail.
right :: Predicatory p => PT p a (Either e a)
-- | Operate on the last value in a foldable, or fail if it's not present.
endingWith :: (Predicatory p, Foldable f) => PT p a (f a)
-- | Operate on the first value in a foldable, or fail if it's not present.
startingWith :: (Predicatory p, Foldable f) => PT p a (f a)
-- | Require that a Fold has a single element, and operate on that
-- element.
soleElementOf :: Predicatory p => Fold s a -> PT p a s
-- | Require that a Foldable has a single element, and operate on
-- that element.
soleElement :: (Predicatory p, Foldable f) => PT p a (f a)
-- | Only test the kth element of a foldable.
kth :: (Predicatory 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 :: Predicatory p => [a -> p] -> [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.
dist :: (Predicatory p, Eq (f ()), Functor f, Foldable f) => f (a -> p) -> f a -> p
-- | Given a representable functor-full of predicates, and a functor-full
-- of values, yield a representable functor-full of booleans. Similar to
-- dist.
distRep :: Representable f => f (a -> p) -> f a -> f p
-- | Test all predicates against one value.
allTrue :: (Predicatory p, Foldable f) => f (a -> p) -> a -> p
-- | 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 :: Predicatory p => Fold 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 :: Predicatory p => (a -> p) -> (b -> p) -> (a, b) -> p
-- | Flipped function composition; f ! for a function f
-- is a predicate transformer.
(!) :: (b -> a) -> (a -> c) -> b -> c
infixr 8 !
-- | Higher precedence $, to work well with !.
(?) :: (a -> b) -> a -> b
infixl 9 ?
-- | 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 :: (Exceptional p, Predicatory 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 :: (Predicatory p, Exceptional p) => (a -> String) -> PT p a a
-- | Predicate which always succeeds.
something :: Predicatory p => a -> p
-- | Predicate which triggers full evaluation of its input and succeeds.
-- Useful for testing that an exception isn't thrown.
forced :: (Predicatory p, NFData a) => a -> p
-- | Predicate on equality.
equals :: (Predicatory p, Eq a) => a -> a -> p
-- | Check that all of the input predicates are satisfied.
satAll :: Predicatory p => [a -> p] -> a -> p
instance GHC.Show.Show PredicateTransformers.PredicateFailed
instance GHC.Exception.Type.Exception PredicateTransformers.PredicateFailed
instance PredicateTransformers.Predicatory (GHC.Types.IO ())
instance PredicateTransformers.Exceptional a => PredicateTransformers.Exceptional (e -> a)
instance PredicateTransformers.Exceptional GHC.Types.Bool
instance PredicateTransformers.Exceptional (GHC.Types.IO ())
instance PredicateTransformers.Predicatory a => PredicateTransformers.Predicatory (e -> a)
instance PredicateTransformers.Predicatory GHC.Types.Bool