Safe Haskell | None |
---|---|
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
- type Pred a = a -> Bool
- type PT a b = Pred a -> Pred b
- match :: APrism s t a b -> PT a s
- nay :: PT a a
- just :: PT a (Maybe a)
- left :: PT e (Either e a)
- right :: PT a (Either e a)
- endingWith :: Foldable f => PT a (f a)
- startingWith :: Foldable f => PT a (f a)
- only :: Foldable f => PT a (f a)
- kth :: Foldable f => Int -> PT a (f a)
- list :: [Pred a] -> Pred [a]
- dist :: (Eq (f ()), Functor f, Foldable f) => f (Pred a) -> Pred (f a)
- distRep :: Representable f => f (a -> Bool) -> f a -> f Bool
- allTrue :: [Pred a] -> Pred a
- allOf1 :: Getting (All, Any) s a -> PT a s
- (==>) :: a -> b -> (a, b)
- pair :: Pred a -> Pred b -> Pred (a, b)
- (!) :: (b -> a) -> (a -> c) -> b -> c
- traced :: Show a => (a -> c) -> a -> c
- traceFailure :: Show a => PT a a
- something :: Pred a
Documentation
endingWith :: Foldable f => PT a (f a) Source #
Operate on the last value in a foldable, or fail if it's not present.
startingWith :: Foldable f => PT a (f a) Source #
Operate on the first value in a foldable, or fail if it's not present.
only :: Foldable f => PT a (f a) Source #
Require that a foldable has a single element, and operate on that element.
list :: [Pred a] -> Pred [a] 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 :: (Eq (f ()), Functor f, Foldable f) => f (Pred a) -> Pred (f a) 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 -> Bool) -> f a -> f Bool Source #
Given a representable functor-full of predicates, and a functor-full of values,
yield a representable functor-full of booleans. Similar to dist
.
allOf1 :: Getting (All, Any) s a -> PT 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.
(!) :: (b -> a) -> (a -> c) -> b -> c Source #
Flipped function composition; f !
for a function f
is a predicate transformer.
traceFailure :: Show a => PT a a Source #
Prints the input of a predicate, if the predicate fails.