| Portability | Rank2Types |
|---|---|
| Stability | provisional |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Safe Haskell | None |
Control.Lens.Fold
Description
A is a generalization of something Fold s aFoldable. It allows
you to extract multiple results from a container. A Foldable container
can be characterized by the behavior of
foldMap :: (.
Since we want to be able to work with monomorphic containers, we could
generalize this signature to Foldable t, Monoid m) => (a -> m) -> t a -> mforall m. ,
and then decorate it with Monoid m => (a -> m) -> s -> mAccessor to obtain
typeFolds a = forall m.Monoidm =>Gettingm s s a a
Every Getter is a valid Fold that simply doesn't use the Monoid
it is passed.
In practice the type we use is slightly more complicated to allow for
better error messages and for it to be transformed by certain
Applicative transformers.
Everything you can do with a Foldable container, you can with with a Fold and there are
combinators that generalize the usual Foldable operations here.
- type Fold s a = forall f. (Gettable f, Applicative f) => (a -> f a) -> s -> f s
- (^..) :: s -> Getting (Endo [a]) s t a b -> [a]
- (^?) :: s -> Getting (First a) s t a b -> Maybe a
- (^?!) :: s -> Getting (First a) s t a b -> a
- preview :: MonadReader s m => Getting (First a) s t a b -> m (Maybe a)
- previews :: MonadReader s m => Getting (First r) s t a b -> (a -> r) -> m (Maybe r)
- folding :: (Foldable f, Applicative g, Gettable g) => (s -> f a) -> LensLike g s t a b
- folded :: Foldable f => Fold (f a) a
- unfolded :: (b -> Maybe (a, b)) -> Fold b a
- iterated :: (a -> a) -> Fold a a
- filtered :: Applicative f => (a -> Bool) -> SimpleLensLike f a a
- backwards :: LensLike (Backwards f) s t a b -> LensLike f s t a b
- repeated :: Fold a a
- replicated :: Int -> Fold a a
- cycled :: (Applicative f, Gettable f) => LensLike f s t a b -> LensLike f s t a b
- takingWhile :: (Gettable f, Applicative f) => (a -> Bool) -> Getting (Endo (f s)) s s a a -> LensLike f s s a a
- droppingWhile :: (Gettable f, Applicative f) => (a -> Bool) -> Getting (Endo (f s, f s)) s s a a -> LensLike f s s a a
- foldMapOf :: Getting r s t a b -> (a -> r) -> s -> r
- foldOf :: Getting a s t a b -> s -> a
- foldrOf :: Getting (Endo r) s t a b -> (a -> r -> r) -> r -> s -> r
- foldlOf :: Getting (Dual (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r
- toListOf :: Getting (Endo [a]) s t a b -> s -> [a]
- anyOf :: Getting Any s t a b -> (a -> Bool) -> s -> Bool
- allOf :: Getting All s t a b -> (a -> Bool) -> s -> Bool
- andOf :: Getting All s t Bool b -> s -> Bool
- orOf :: Getting Any s t Bool b -> s -> Bool
- productOf :: Getting (Product a) s t a b -> s -> a
- sumOf :: Getting (Sum a) s t a b -> s -> a
- traverseOf_ :: Functor f => Getting (Traversed f) s t a b -> (a -> f r) -> s -> f ()
- forOf_ :: Functor f => Getting (Traversed f) s t a b -> s -> (a -> f r) -> f ()
- sequenceAOf_ :: Functor f => Getting (Traversed f) s t (f a) b -> s -> f ()
- mapMOf_ :: Monad m => Getting (Sequenced m) s t a b -> (a -> m r) -> s -> m ()
- forMOf_ :: Monad m => Getting (Sequenced m) s t a b -> s -> (a -> m r) -> m ()
- sequenceOf_ :: Monad m => Getting (Sequenced m) s t (m a) b -> s -> m ()
- asumOf :: Alternative f => Getting (Endo (f a)) s t (f a) b -> s -> f a
- msumOf :: MonadPlus m => Getting (Endo (m a)) s t (m a) b -> s -> m a
- concatMapOf :: Getting [r] s t a b -> (a -> [r]) -> s -> [r]
- concatOf :: Getting [r] s t [r] b -> s -> [r]
- elemOf :: Eq a => Getting Any s t a b -> a -> s -> Bool
- notElemOf :: Eq a => Getting All s t a b -> a -> s -> Bool
- lengthOf :: Getting (Sum Int) s t a b -> s -> Int
- nullOf :: Getting All s t a b -> s -> Bool
- notNullOf :: Getting Any s t a b -> s -> Bool
- firstOf :: Getting (First a) s t a b -> s -> Maybe a
- lastOf :: Getting (Last a) s t a b -> s -> Maybe a
- maximumOf :: Getting (Max a) s t a b -> s -> Maybe a
- minimumOf :: Getting (Min a) s t a b -> s -> Maybe a
- maximumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a
- minimumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a
- findOf :: Getting (First a) s t a b -> (a -> Bool) -> s -> Maybe a
- foldrOf' :: Getting (Dual (Endo (r -> r))) s t a b -> (a -> r -> r) -> r -> s -> r
- foldlOf' :: Getting (Endo (r -> r)) s t a b -> (r -> a -> r) -> r -> s -> r
- foldr1Of :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> a) -> s -> a
- foldl1Of :: Getting (Dual (Endo (Maybe a))) s t a b -> (a -> a -> a) -> s -> a
- foldrMOf :: Monad m => Getting (Dual (Endo (r -> m r))) s t a b -> (a -> r -> m r) -> r -> s -> m r
- foldlMOf :: Monad m => Getting (Endo (r -> m r)) s t a b -> (r -> a -> m r) -> r -> s -> m r
- newtype ReifiedFold s a = ReifyFold {
- reflectFold :: Fold s a
- headOf :: Getting (First a) s t a b -> s -> Maybe a
Folds
type Fold s a = forall f. (Gettable f, Applicative f) => (a -> f a) -> s -> f sSource
A Fold describes how to retrieve multiple values in a way that can be composed
with other lens-like constructions.
A provides a structure with operations very similar to those of the Fold s aFoldable
typeclass, see foldMapOf and the other Fold combinators.
By convention, if there exists a foo method that expects a , then there should be a
Foldable (f a)fooOf method that takes a and a value of type Fold s as.
A Getter is a legal Fold that just ignores the supplied Monoid
Unlike a Traversal a Fold is read-only. Since a Fold cannot be used to write back
there are no lens laws that apply.
(^..) :: s -> Getting (Endo [a]) s t a b -> [a]Source
A convenient infix (flipped) version of toListOf.
>>>[[1,2],[3]]^..traverse.traverse[1,2,3]
>>>(1,2)^..both[1,2]
toListxs ≡ xs^..folded(^..) ≡fliptoListOf
(^..) :: s ->Getters a -> [a] (^..) :: s ->Folds a -> [a] (^..) :: s ->SimpleLenss a -> [a] (^..) :: s ->SimpleIsos a -> [a] (^..) :: s ->SimpleTraversals a -> [a] (^..) :: s ->SimplePrisms a -> [a]
(^?) :: s -> Getting (First a) s t a b -> Maybe aSource
Perform a safe head of a Fold or Traversal or retrieve Just the result
from a Getter or Lens.
When using a Traversal as a partial Lens, or a Fold as a partial Getter this can be a convenient
way to extract the optional value.
(^?) ≡flippreview
(^?) :: s ->Getters a ->Maybea (^?) :: s ->Folds a ->Maybea (^?) :: s ->SimpleLenss a ->Maybea (^?) :: s ->SimpleIsos a ->Maybea (^?) :: s ->SimpleTraversals a ->Maybea
preview :: MonadReader s m => Getting (First a) s t a b -> m (Maybe a)Source
Retrieve the first value targeted by a Fold or Traversal (or Just the result
from a Getter or Lens). See also (^?).
listToMaybe.toList≡previewfolded
This is usually applied in the reader monad (->) s.
preview::Getters a -> s ->Maybeapreview::Folds a -> s ->Maybeapreview::SimpleLenss a -> s ->Maybeapreview::SimpleIsos a -> s ->Maybeapreview::SimpleTraversals a -> s ->Maybea
However, it may be useful to think of its full generality when working with a monad transformer stack:
preview:: MonadReader s m =>Getters a -> m (Maybea)preview:: MonadReader s m =>Folds a -> m (Maybea)preview:: MonadReader s m =>SimpleLenss a -> m (Maybea)preview:: MonadReader s m =>SimpleIsos a -> m (Maybea)preview:: MonadReader s m =>SimpleTraversals a -> m (Maybea)
previews :: MonadReader s m => Getting (First r) s t a b -> (a -> r) -> m (Maybe r)Source
Retrieve a function of the first value targeted by a Fold or
Traversal (or Just the result from a Getter or Lens).
This is usually applied in the reader monad (->) s.
previews::Getters a -> (a -> r) -> s ->Maybeapreviews::Folds a -> (a -> r) -> s ->Maybeapreviews::SimpleLenss a -> (a -> r) -> s ->Maybeapreviews::SimpleIsos a -> (a -> r) -> s ->Maybeapreviews::SimpleTraversals a -> (a -> r) -> s ->Maybea
However, it may be useful to think of its full generality when working with a monad transformer stack:
previews:: MonadReader s m =>Getters a -> (a -> r) -> m (Mayber)previews:: MonadReader s m =>Folds a -> (a -> r) -> m (Mayber)previews:: MonadReader s m =>SimpleLenss a -> (a -> r) -> m (Mayber)previews:: MonadReader s m =>SimpleIsos a -> (a -> r) -> m (Mayber)previews:: MonadReader s m =>SimpleTraversals a -> (a -> r) -> m (Mayber)
Building Folds
filtered :: Applicative f => (a -> Bool) -> SimpleLensLike f a aSource
Obtain a Fold that can be composed with to filter another Lens, Iso, Getter, Fold (or Traversal)
Note: This is not a legal Traversal, unless you are very careful not to invalidate the predicate on the target.
As a counter example, consider that given evens = the second filtered evenTraversal law is violated:
overevenssucc.overevenssucc/=overevens (succ.succ)
So, in order for this to qualify as a legal Traversal you can only use it for actions that preserve the result of the predicate!
filtered:: (a ->Bool) ->Folda a
backwards :: LensLike (Backwards f) s t a b -> LensLike f s t a bSource
This allows you to traverse the elements of a Traversal or Fold in the opposite order.
This will demote an IndexedTraversal or IndexedFold to a regular Traversal or Fold,
respectively; to preserve the indices, use ibackwards instead.
Note: backwards should have no impact on a Getter, Setter, Lens or Iso.
replicated :: Int -> Fold a aSource
A fold that replicates its input n times.
replicaten ≡toListOf(replicatedn)
>>>5^..replicated 20[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]
cycled :: (Applicative f, Gettable f) => LensLike f s t a b -> LensLike f s t a bSource
Transform a fold into a fold that loops over its elements over and over.
>>>[1,2,3]^..taking 7 (cycled traverse)[1,2,3,1,2,3,1]
takingWhile :: (Gettable f, Applicative f) => (a -> Bool) -> Getting (Endo (f s)) s s a a -> LensLike f s s a aSource
droppingWhile :: (Gettable f, Applicative f) => (a -> Bool) -> Getting (Endo (f s, f s)) s s a a -> LensLike f s s a aSource
Folding
foldMapOf :: Getting r s t a b -> (a -> r) -> s -> rSource
foldMap=foldMapOffolded
foldMapOf≡views
foldMapOf::Getters a -> (a -> r) -> s -> rfoldMapOf::Monoidr =>Folds a -> (a -> r) -> s -> rfoldMapOf::SimpleLenss a -> (a -> r) -> s -> rfoldMapOf::SimpleIsos a -> (a -> r) -> s -> rfoldMapOf::Monoidr =>SimpleTraversals a -> (a -> r) -> s -> rfoldMapOf::Monoidr =>SimplePrisms a -> (a -> r) -> s -> r
foldrOf :: Getting (Endo r) s t a b -> (a -> r -> r) -> r -> s -> rSource
Right-associative fold of parts of a structure that are viewed through a Lens, Getter, Fold or Traversal.
foldr≡foldrOffolded
foldrOf::Getters a -> (a -> r -> r) -> r -> s -> rfoldrOf::Folds a -> (a -> r -> r) -> r -> s -> rfoldrOf::SimpleLenss a -> (a -> r -> r) -> r -> s -> rfoldrOf::SimpleIsos a -> (a -> r -> r) -> r -> s -> rfoldrOf::SimpleTraversals a -> (a -> r -> r) -> r -> s -> rfoldrOf::SimplePrisms a -> (a -> r -> r) -> r -> s -> r
foldlOf :: Getting (Dual (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> rSource
Left-associative fold of the parts of a structure that are viewed through a Lens, Getter, Fold or Traversal.
foldl≡foldlOffolded
foldlOf::Getters a -> (r -> a -> r) -> r -> s -> rfoldlOf::Folds a -> (r -> a -> r) -> r -> s -> rfoldlOf::SimpleLenss a -> (r -> a -> r) -> r -> s -> rfoldlOf::SimpleIsos a -> (r -> a -> r) -> r -> s -> rfoldlOf::SimpleTraversals a -> (r -> a -> r) -> r -> s -> rfoldlOf::SimplePrisms a -> (r -> a -> r) -> r -> s -> r
anyOf :: Getting Any s t a b -> (a -> Bool) -> s -> BoolSource
Returns True if any target of a Fold satisfies a predicate.
>>>anyOf both (=='x') ('x','y')True>>>import Data.Data.Lens>>>anyOf biplate (== "world") (((),2::Int),"hello",("world",11))True
any≡anyOffolded
anyOf::Getters a -> (a ->Bool) -> s ->BoolanyOf::Folds a -> (a ->Bool) -> s ->BoolanyOf::SimpleLenss a -> (a ->Bool) -> s ->BoolanyOf::SimpleIsos a -> (a ->Bool) -> s ->BoolanyOf::SimpleTraversals a -> (a ->Bool) -> s ->BoolanyOf::SimplePrisms a -> (a ->Bool) -> s ->Bool
allOf :: Getting All s t a b -> (a -> Bool) -> s -> BoolSource
Returns True if every target of a Fold satisfies a predicate.
>>>allOf both (>=3) (4,5)True>>>allOf folded (>=2) [1..10]False
all≡allOffolded
allOf::Getters a -> (a ->Bool) -> s ->BoolallOf::Folds a -> (a ->Bool) -> s ->BoolallOf::SimpleLenss a -> (a ->Bool) -> s ->BoolallOf::SimpleIsos a -> (a ->Bool) -> s ->BoolallOf::SimpleTraversals a -> (a ->Bool) -> s ->BoolallOf::SimplePrisms a -> (a ->Bool) -> s ->Bool
andOf :: Getting All s t Bool b -> s -> BoolSource
Returns True if every target of a Fold is True.
>>>andOf both (True,False)False>>>andOf both (True,True)True
and≡andOffolded
andOf::GettersBool-> s ->BoolandOf::FoldsBool-> s ->BoolandOf::SimpleLenssBool-> s ->BoolandOf::SimpleIsosBool-> s ->BoolandOf::SimpleTraversalsBool-> s ->BoolandOf::SimplePrismsBool-> s ->Bool
orOf :: Getting Any s t Bool b -> s -> BoolSource
Returns True if any target of a Fold is True.
>>>orOf both (True,False)True>>>orOf both (False,False)False
or≡orOffolded
orOf::GettersBool-> s ->BoolorOf::FoldsBool-> s ->BoolorOf::SimpleLenssBool-> s ->BoolorOf::SimpleIsosBool-> s ->BoolorOf::SimpleTraversalsBool-> s ->BoolorOf::SimplePrismsBool-> s ->Bool
productOf :: Getting (Product a) s t a b -> s -> aSource
Calculate the product of every number targeted by a Fold
>>>productOf both (4,5)20>>>productOf folded [1,2,3,4,5]120
product≡productOffolded
productOf::Getters a -> s -> aproductOf::Numa =>Folds a -> s -> aproductOf::SimpleLenss a -> s -> aproductOf::SimpleIsos a -> s -> aproductOf::Numa =>SimpleTraversals a -> s -> aproductOf::Numa =>SimplePrisms a -> s -> a
sumOf :: Getting (Sum a) s t a b -> s -> aSource
Calculate the sum of every number targeted by a Fold.
>>>sumOf both (5,6)11>>>sumOf folded [1,2,3,4]10>>>sumOf (folded.both) [(1,2),(3,4)]10>>>import Data.Data.Lens>>>sumOf biplate [(1::Int,[]),(2,[(3::Int,4::Int)])] :: Int10
sum≡sumOffolded
sumOf_1:: (a, b) -> asumOf(folded._1) :: (Foldablef,Numa) => f (a, b) -> a
sumOf::Getters a -> s -> asumOf::Numa =>Folds a -> s -> asumOf::SimpleLenss a -> s -> asumOf::SimpleIsos a -> s -> asumOf::Numa =>SimpleTraversals a -> s -> asumOf::Numa =>SimplePrisms a -> s -> a
traverseOf_ :: Functor f => Getting (Traversed f) s t a b -> (a -> f r) -> s -> f ()Source
Traverse over all of the targets of a Fold (or Getter), computing an Applicative (or Functor) -based answer,
but unlike traverseOf do not construct a new structure. traverseOf_ generalizes
traverse_ to work over any Fold.
When passed a Getter, traverseOf_ can work over any Functor, but when passed a Fold, traverseOf_ requires
an Applicative.
>>>traverseOf_ both putStrLn ("hello","world")hello world
traverse_≡traverseOf_folded
traverseOf__2::Functorf => (c -> f r) -> (d, c) -> f ()traverseOf_traverseLeft::Applicativef => (a -> f b) ->Eithera c -> f ()
The rather specific signature of traverseOf_ allows it to be used as if the signature was any of:
traverseOf_::Functorf =>Getters a -> (a -> f r) -> s -> f ()traverseOf_::Applicativef =>Folds a -> (a -> f r) -> s -> f ()traverseOf_::Functorf =>SimpleLenss a -> (a -> f r) -> s -> f ()traverseOf_::Functorf =>SimpleIsos a -> (a -> f r) -> s -> f ()traverseOf_::Applicativef =>SimpleTraversals a -> (a -> f r) -> s -> f ()traverseOf_::Applicativef =>SimplePrisms a -> (a -> f r) -> s -> f ()
forOf_ :: Functor f => Getting (Traversed f) s t a b -> s -> (a -> f r) -> f ()Source
Traverse over all of the targets of a Fold (or Getter), computing an Applicative (or Functor) -based answer,
but unlike forOf do not construct a new structure. forOf_ generalizes
for_ to work over any Fold.
When passed a Getter, forOf_ can work over any Functor, but when passed a Fold, forOf_ requires
an Applicative.
for_≡forOf_folded
The rather specific signature of forOf_ allows it to be used as if the signature was any of:
forOf_::Functorf =>Getters a -> s -> (a -> f r) -> f ()forOf_::Applicativef =>Folds a -> s -> (a -> f r) -> f ()forOf_::Functorf =>SimpleLenss a -> s -> (a -> f r) -> f ()forOf_::Functorf =>SimpleIsos a -> s -> (a -> f r) -> f ()forOf_::Applicativef =>SimpleTraversals a -> s -> (a -> f r) -> f ()forOf_::Applicativef =>SimplePrisms a -> s -> (a -> f r) -> f ()
sequenceAOf_ :: Functor f => Getting (Traversed f) s t (f a) b -> s -> f ()Source
Evaluate each action in observed by a Fold on a structure from left to right, ignoring the results.
sequenceA_≡sequenceAOf_folded
sequenceAOf_::Functorf =>Getters (f a) -> s -> f ()sequenceAOf_::Applicativef =>Folds (f a) -> s -> f ()sequenceAOf_::Functorf =>SimpleLenss (f a) -> s -> f ()sequenceAOf_::Functorf =>SimpleIsos (f a) -> s -> f ()sequenceAOf_::Applicativef =>SimpleTraversals (f a) -> s -> f ()sequenceAOf_::Applicativef =>SimplePrisms (f a) -> s -> f ()
mapMOf_ :: Monad m => Getting (Sequenced m) s t a b -> (a -> m r) -> s -> m ()Source
Map each target of a Fold on a structure to a monadic action, evaluate these actions from left to right, and ignore the results.
mapM_≡mapMOf_folded
mapMOf_::Monadm =>Getters a -> (a -> m r) -> s -> m ()mapMOf_::Monadm =>Folds a -> (a -> m r) -> s -> m ()mapMOf_::Monadm =>SimpleLenss a -> (a -> m r) -> s -> m ()mapMOf_::Monadm =>SimpleIsos a -> (a -> m r) -> s -> m ()mapMOf_::Monadm =>SimpleTraversals a -> (a -> m r) -> s -> m ()mapMOf_::Monadm =>SimplePrisms a -> (a -> m r) -> s -> m ()
forMOf_ :: Monad m => Getting (Sequenced m) s t a b -> s -> (a -> m r) -> m ()Source
forMOf_ is mapMOf_ with two of its arguments flipped.
forM_≡forMOf_folded
forMOf_::Monadm =>Getters a -> s -> (a -> m r) -> m ()forMOf_::Monadm =>Folds a -> s -> (a -> m r) -> m ()forMOf_::Monadm =>SimpleLenss a -> s -> (a -> m r) -> m ()forMOf_::Monadm =>SimpleIsos a -> s -> (a -> m r) -> m ()forMOf_::Monadm =>SimpleTraversals a -> s -> (a -> m r) -> m ()forMOf_::Monadm =>SimplePrisms a -> s -> (a -> m r) -> m ()
sequenceOf_ :: Monad m => Getting (Sequenced m) s t (m a) b -> s -> m ()Source
Evaluate each monadic action referenced by a Fold on the structure from left to right, and ignore the results.
sequence_≡sequenceOf_folded
sequenceOf_::Monadm =>Getters (m a) -> s -> m ()sequenceOf_::Monadm =>Folds (m a) -> s -> m ()sequenceOf_::Monadm =>SimpleLenss (m a) -> s -> m ()sequenceOf_::Monadm =>SimpleIsos (m a) -> s -> m ()sequenceOf_::Monadm =>SimpleTraversals (m a) -> s -> m ()sequenceOf_::Monadm =>SimplePrisms (m a) -> s -> m ()
asumOf :: Alternative f => Getting (Endo (f a)) s t (f a) b -> s -> f aSource
The sum of a collection of actions, generalizing concatOf.
asum≡asumOffolded
asumOf::Alternativef =>Getters a -> s -> f aasumOf::Alternativef =>Folds a -> s -> f aasumOf::Alternativef =>SimpleLenss a -> s -> f aasumOf::Alternativef =>SimpleIsos a -> s -> f aasumOf::Alternativef =>SimpleTraversals a -> s -> f aasumOf::Alternativef =>SimplePrisms a -> s -> f a
msumOf :: MonadPlus m => Getting (Endo (m a)) s t (m a) b -> s -> m aSource
The sum of a collection of actions, generalizing concatOf.
msum≡msumOffolded
msumOf::MonadPlusm =>Getters a -> s -> m amsumOf::MonadPlusm =>Folds a -> s -> m amsumOf::MonadPlusm =>SimpleLenss a -> s -> m amsumOf::MonadPlusm =>SimpleIsos a -> s -> m amsumOf::MonadPlusm =>SimpleTraversals a -> s -> m amsumOf::MonadPlusm =>SimplePrisms a -> s -> m a
concatMapOf :: Getting [r] s t a b -> (a -> [r]) -> s -> [r]Source
Map a function over all the targets of a Fold of a container and concatenate the resulting lists.
concatMap≡concatMapOffolded
concatMapOf::Getters a -> (a -> [r]) -> s -> [r]concatMapOf::Folds a -> (a -> [r]) -> s -> [r]concatMapOf::SimpleLenss a -> (a -> [r]) -> s -> [r]concatMapOf::SimpleIsos a -> (a -> [r]) -> s -> [r]concatMapOf::SimpleTraversals a -> (a -> [r]) -> s -> [r]
concatOf :: Getting [r] s t [r] b -> s -> [r]Source
Concatenate all of the lists targeted by a Fold into a longer list.
>>>concatOf both ("pan","ama")"panama"
concat≡concatOffoldedconcatOf≡view
concatOf::Getters [r] -> s -> [r]concatOf::Folds [r] -> s -> [r]concatOf::SimpleIsos [r] -> s -> [r]concatOf::SimpleLenss [r] -> s -> [r]concatOf::SimpleTraversals [r] -> s -> [r]
elemOf :: Eq a => Getting Any s t a b -> a -> s -> BoolSource
Does the element occur anywhere within a given Fold of the structure?
>>>elemOf both "hello" ("hello","world")True
elem≡elemOffolded
elemOf::Eqa =>Getters a -> a -> s ->BoolelemOf::Eqa =>Folds a -> a -> s ->BoolelemOf::Eqa =>SimpleLenss a -> a -> s ->BoolelemOf::Eqa =>SimpleIsos a -> a -> s ->BoolelemOf::Eqa =>SimpleTraversals a -> a -> s ->BoolelemOf::Eqa =>SimplePrisms a -> a -> s ->Bool
notElemOf :: Eq a => Getting All s t a b -> a -> s -> BoolSource
Does the element not occur anywhere within a given Fold of the structure?
notElem≡notElemOffolded
notElemOf::Eqa =>Getters a -> a -> s ->BoolnotElemOf::Eqa =>Folds a -> a -> s ->BoolnotElemOf::Eqa =>SimpleIsos a -> a -> s ->BoolnotElemOf::Eqa =>SimpleLenss a -> a -> s ->BoolnotElemOf::Eqa =>SimpleTraversals a -> a -> s ->BoolnotElemOf::Eqa =>SimplePrisms a -> a -> s ->Bool
lengthOf :: Getting (Sum Int) s t a b -> s -> IntSource
Note: this can be rather inefficient for large containers.
length≡lengthOffolded
>>>lengthOf _1 ("hello",())1
lengthOf(folded.folded) ::Foldablef => f (g a) ->Int
lengthOf::Getters a -> s ->IntlengthOf::Folds a -> s ->IntlengthOf::SimpleLenss a -> s ->IntlengthOf::SimpleIsos a -> s ->IntlengthOf::SimpleTraversals a -> s ->Int
nullOf :: Getting All s t a b -> s -> BoolSource
Returns True if this Fold or Traversal has no targets in the given container.
Note: nullOf on a valid Iso, Lens or Getter should always return False
null≡nullOffolded
This may be rather inefficient compared to the null check of many containers.
>>>nullOf _1 (1,2)False
nullOf(folded._1.folded) ::Foldablef => f (g a, b) ->Bool
nullOf::Getters a -> s ->BoolnullOf::Folds a -> s ->BoolnullOf::SimpleIsos a -> s ->BoolnullOf::SimpleLenss a -> s ->BoolnullOf::SimpleTraversals a -> s ->Bool
notNullOf :: Getting Any s t a b -> s -> BoolSource
Returns True if this Fold or Traversal has any targets in the given container.
Note: notNullOf on a valid Iso, Lens or Getter should always return True
null≡notNullOffolded
This may be rather inefficient compared to the check of many containers.
not . null
>>>notNullOf _1 (1,2)True
notNullOf(folded._1.folded) ::Foldablef => f (g a, b) ->Bool
notNullOf::Getters a -> s ->BoolnotNullOf::Folds a -> s ->BoolnotNullOf::SimpleIsos a -> s ->BoolnotNullOf::SimpleLenss a -> s ->BoolnotNullOf::SimpleTraversals a -> s ->Bool
firstOf :: Getting (First a) s t a b -> s -> Maybe aSource
Retrieve the First entry of a Fold or Traversal or retrieve Just the result
from a Getter or Lens.
firstOf::Getters a -> s ->MaybeafirstOf::Folds a -> s ->MaybeafirstOf::SimpleLenss a -> s ->MaybeafirstOf::SimpleIsos a -> s ->MaybeafirstOf::SimpleTraversals a -> s ->Maybea
maximumOf :: Getting (Max a) s t a b -> s -> Maybe aSource
Obtain the maximum element (if any) targeted by a Fold or Traversal
Note: maximumOf on a valid Iso, Lens or Getter will always return Just a value.
maximum≡fromMaybe(errorempty).maximumOffolded
maximumOf::Getters a -> s ->MaybeamaximumOf::Orda =>Folds a -> s ->MaybeamaximumOf::SimpleIsos a -> s ->MaybeamaximumOf::SimpleLenss a -> s ->MaybeamaximumOf::Orda =>SimpleTraversals a -> s ->Maybea
minimumOf :: Getting (Min a) s t a b -> s -> Maybe aSource
Obtain the minimum element (if any) targeted by a Fold or Traversal
Note: minimumOf on a valid Iso, Lens or Getter will always return Just a value.
minimum≡fromMaybe(errorempty).minimumOffolded
minimumOf::Getters a -> s ->MaybeaminimumOf::Orda =>Folds a -> s ->MaybeaminimumOf::SimpleIsos a -> s ->MaybeaminimumOf::SimpleLenss a -> s ->MaybeaminimumOf::Orda =>SimpleTraversals a -> s ->Maybea
maximumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe aSource
Obtain the maximum element (if any) targeted by a Fold, Traversal, Lens, Iso,
or Getter according to a user supplied ordering.
maximumBycmp ≡fromMaybe(errorempty).maximumByOffoldedcmp
maximumByOf::Getters a -> (a -> a ->Ordering) -> s ->MaybeamaximumByOf::Folds a -> (a -> a ->Ordering) -> s ->MaybeamaximumByOf::SimpleIsos a -> (a -> a ->Ordering) -> s ->MaybeamaximumByOf::SimpleLenss a -> (a -> a ->Ordering) -> s ->MaybeamaximumByOf::SimpleTraversals a -> (a -> a ->Ordering) -> s ->Maybea
minimumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe aSource
Obtain the minimum element (if any) targeted by a Fold, Traversal, Lens, Iso
or Getter according to a user supplied ordering.
minimumBycmp ≡fromMaybe(errorempty).minimumByOffoldedcmp
minimumByOf::Getters a -> (a -> a ->Ordering) -> s ->MaybeaminimumByOf::Folds a -> (a -> a ->Ordering) -> s ->MaybeaminimumByOf::SimpleIsos a -> (a -> a ->Ordering) -> s ->MaybeaminimumByOf::SimpleLenss a -> (a -> a ->Ordering) -> s ->MaybeaminimumByOf::SimpleTraversals a -> (a -> a ->Ordering) -> s ->Maybea
findOf :: Getting (First a) s t a b -> (a -> Bool) -> s -> Maybe aSource
The findOf function takes a Lens (or Getter, Iso, Fold, or Traversal),
a predicate and a structure and returns the leftmost element of the structure
matching the predicate, or Nothing if there is no such element.
findOf::Getters a -> (a ->Bool) -> s ->MaybeafindOf::Folds a -> (a ->Bool) -> s ->MaybeafindOf::SimpleIsos a -> (a ->Bool) -> s ->MaybeafindOf::SimpleLenss a -> (a ->Bool) -> s ->MaybeafindOf::SimpleTraversals a -> (a ->Bool) -> s ->Maybea
foldrOf' :: Getting (Dual (Endo (r -> r))) s t a b -> (a -> r -> r) -> r -> s -> rSource
Strictly fold right over the elements of a structure.
foldr'≡foldrOf'folded
foldrOf'::Getters a -> (a -> r -> r) -> r -> s -> rfoldrOf'::Folds a -> (a -> r -> r) -> r -> s -> rfoldrOf'::SimpleIsos a -> (a -> r -> r) -> r -> s -> rfoldrOf'::SimpleLenss a -> (a -> r -> r) -> r -> s -> rfoldrOf'::SimpleTraversals a -> (a -> r -> r) -> r -> s -> r
foldlOf' :: Getting (Endo (r -> r)) s t a b -> (r -> a -> r) -> r -> s -> rSource
Fold over the elements of a structure, associating to the left, but strictly.
foldl'≡foldlOf'folded
foldlOf'::Getters a -> (r -> a -> r) -> r -> s -> rfoldlOf'::Folds a -> (r -> a -> r) -> r -> s -> rfoldlOf'::SimpleIsos a -> (r -> a -> r) -> r -> s -> rfoldlOf'::SimpleLenss a -> (r -> a -> r) -> r -> s -> rfoldlOf'::SimpleTraversals a -> (r -> a -> r) -> r -> s -> r
foldr1Of :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> a) -> s -> aSource
A variant of foldrOf that has no base case and thus may only be applied
to lenses and structures such that the lens views at least one element of
the structure.
foldr1Ofl f ≡foldr1f.toListOflfoldr1≡foldr1Offolded
foldr1Of::Getters a -> (a -> a -> a) -> s -> afoldr1Of::Folds a -> (a -> a -> a) -> s -> afoldr1Of::SimpleIsos a -> (a -> a -> a) -> s -> afoldr1Of::SimpleLenss a -> (a -> a -> a) -> s -> afoldr1Of::SimpleTraversals a -> (a -> a -> a) -> s -> a
foldl1Of :: Getting (Dual (Endo (Maybe a))) s t a b -> (a -> a -> a) -> s -> aSource
A variant of foldlOf that has no base case and thus may only be applied to lenses and structures such
that the lens views at least one element of the structure.
foldl1Ofl f ≡foldl1Ofl f .toListfoldl1≡foldl1Offolded
foldl1Of::Getters a -> (a -> a -> a) -> s -> afoldl1Of::Folds a -> (a -> a -> a) -> s -> afoldl1Of::SimpleIsos a -> (a -> a -> a) -> s -> afoldl1Of::SimpleLenss a -> (a -> a -> a) -> s -> afoldl1Of::SimpleTraversals a -> (a -> a -> a) -> s -> a
foldrMOf :: Monad m => Getting (Dual (Endo (r -> m r))) s t a b -> (a -> r -> m r) -> r -> s -> m rSource
Monadic fold over the elements of a structure, associating to the right, i.e. from right to left.
foldrM≡foldrMOffolded
foldrMOf::Monadm =>Getters a -> (a -> r -> m r) -> r -> s -> m rfoldrMOf::Monadm =>Folds a -> (a -> r -> m r) -> r -> s -> m rfoldrMOf::Monadm =>SimpleIsos a -> (a -> r -> m r) -> r -> s -> m rfoldrMOf::Monadm =>SimpleLenss a -> (a -> r -> m r) -> r -> s -> m rfoldrMOf::Monadm =>SimpleTraversals a -> (a -> r -> m r) -> r -> s -> m r
foldlMOf :: Monad m => Getting (Endo (r -> m r)) s t a b -> (r -> a -> m r) -> r -> s -> m rSource
Monadic fold over the elements of a structure, associating to the left, i.e. from left to right.
foldlM≡foldlMOffolded
foldlMOf::Monadm =>Getters a -> (r -> a -> m r) -> r -> s -> m rfoldlMOf::Monadm =>Folds a -> (r -> a -> m r) -> r -> s -> m rfoldlMOf::Monadm =>SimpleIsos a -> (r -> a -> m r) -> r -> s -> m rfoldlMOf::Monadm =>SimpleLenss a -> (r -> a -> m r) -> r -> s -> m rfoldlMOf::Monadm =>SimpleTraversals a -> (r -> a -> m r) -> r -> s -> m r
Storing Folds
newtype ReifiedFold s a Source
Useful for storing folds in containers.
Constructors
| ReifyFold | |
Fields
| |