Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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)
Synopsis
- class Predicatory a where
- class Exceptional a where
- data PredicateFailed = PredicateFailed
- type Pred a = a -> Bool
- type PT p a b = (a -> p) -> b -> p
- match :: Predicatory p => APrism s t a b -> PT p a s
- just :: Predicatory p => PT p a (Maybe a)
- left :: Predicatory p => PT p e (Either e a)
- right :: Predicatory p => PT p a (Either e a)
- endingWith :: (Predicatory p, Foldable f) => PT p a (f a)
- startingWith :: (Predicatory p, Foldable f) => PT p a (f a)
- only :: (Predicatory p, Foldable f) => PT p a (f a)
- kth :: (Predicatory p, Foldable f) => Int -> PT p a (f a)
- list :: Predicatory p => [a -> p] -> [a] -> p
- dist :: (Predicatory p, Eq (f ()), Functor f, Foldable f) => f (a -> p) -> f a -> p
- distRep :: Representable f => f (a -> p) -> f a -> f p
- allTrue :: (Predicatory p, Foldable f) => f (a -> p) -> a -> p
- allOf1 :: Predicatory p => Fold s a -> PT p a s
- pattern (:=>) :: a -> b -> (a, b)
- pair :: Predicatory p => (a -> p) -> (b -> p) -> (a, b) -> p
- (!) :: (b -> a) -> (a -> c) -> b -> c
- traced :: Show a => (a -> c) -> a -> c
- traceFail :: (Predicatory p, Exceptional p) => (a -> String) -> PT p a a
- traceFailShow :: (Exceptional p, Predicatory p, Show a) => PT p a a
- traceFailFun :: (Predicatory p, Exceptional p) => (e -> a -> String) -> PT (e -> p) a a
- something :: Predicatory p => a -> p
- forced :: (Predicatory p, NFData a) => a -> p
Documentation
class Predicatory a where Source #
Instances
Predicatory Bool Source # | |
Predicatory (IO ()) Source # | |
Predicatory a => Predicatory (e -> a) Source # | |
class Exceptional a where Source #
Instances
Exceptional Bool Source # | |
Exceptional (IO ()) Source # | |
data PredicateFailed Source #
Instances
Exception PredicateFailed Source # | |
Defined in PredicateTransformers | |
Show PredicateFailed Source # | |
Defined in PredicateTransformers showsPrec :: Int -> PredicateFailed -> ShowS # show :: PredicateFailed -> String # showList :: [PredicateFailed] -> ShowS # |
match :: Predicatory p => APrism s t a b -> PT p a s Source #
Operate on the target of a prism, or fail.
endingWith :: (Predicatory p, Foldable f) => PT p a (f a) Source #
Operate on the last value in a foldable, or fail if it's not present.
startingWith :: (Predicatory p, Foldable f) => PT p a (f a) Source #
Operate on the first value in a foldable, or fail if it's not present.
only :: (Predicatory p, Foldable f) => PT p a (f a) Source #
Require that a foldable has a single element, and operate on that element.
kth :: (Predicatory p, Foldable f) => Int -> PT p a (f a) Source #
Only test the k
th element of a foldable.
list :: Predicatory p => [a -> p] -> [a] -> p Source #
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.
dist :: (Predicatory p, Eq (f ()), Functor f, Foldable f) => f (a -> p) -> f a -> p Source #
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
.
distRep :: Representable f => f (a -> p) -> f a -> f p Source #
Given a representable functor-full of predicates, and a functor-full of values,
yield a representable functor-full of booleans. Similar to dist
.
allTrue :: (Predicatory p, Foldable f) => f (a -> p) -> a -> p Source #
Test all predicates against one value.
allOf1 :: Predicatory p => Fold s a -> PT p a s Source #
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.
pair :: Predicatory p => (a -> p) -> (b -> p) -> (a, b) -> p Source #
(!) :: (b -> a) -> (a -> c) -> b -> c Source #
Flipped function composition; f !
for a function f
is a predicate transformer.
traceFail :: (Predicatory p, Exceptional p) => (a -> String) -> PT p a a Source #
Prints the input of a predicate, if the predicate fails. Requires that the predicate's output type includes a notion of failure.
traceFailShow :: (Exceptional p, Predicatory p, Show a) => PT p a a Source #
traceFailFun :: (Predicatory p, Exceptional p) => (e -> a -> String) -> PT (e -> p) a a Source #
Prints the input of a predicate over functions, if the predicate fails. Requires that the predicate's output type includes a notion of failure.
something :: Predicatory p => a -> p Source #
Predicate which always succeeds.
forced :: (Predicatory p, NFData a) => a -> p Source #
Predicate which triggers full evaluation of its input and succeeds. Useful for testing that an exception isn't thrown.