| Portability | rank 2 types, MPTCs, TFs, flexible |
|---|---|
| Stability | provisional |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Safe Haskell | None |
Control.Lens.IndexedFold
Contents
Description
- type IndexedFold i s a = forall k f. (Indexable i k, Applicative f, Gettable f) => k (a -> f a) (s -> f s)
- ifoldMapOf :: IndexedGetting i m s t a b -> (i -> a -> m) -> s -> m
- ifoldrOf :: IndexedGetting i (Endo r) s t a b -> (i -> a -> r -> r) -> r -> s -> r
- ifoldlOf :: IndexedGetting i (Dual (Endo r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r
- ianyOf :: IndexedGetting i Any s t a b -> (i -> a -> Bool) -> s -> Bool
- iallOf :: IndexedGetting i All s t a b -> (i -> a -> Bool) -> s -> Bool
- itraverseOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> (i -> a -> f r) -> s -> f ()
- iforOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> s -> (i -> a -> f r) -> f ()
- imapMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> (i -> a -> m r) -> s -> m ()
- iforMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> s -> (i -> a -> m r) -> m ()
- iconcatMapOf :: IndexedGetting i [r] s t a b -> (i -> a -> [r]) -> s -> [r]
- ifindOf :: IndexedGetting i (First (i, a)) s t a b -> (i -> a -> Bool) -> s -> Maybe (i, a)
- ifoldrOf' :: IndexedGetting i (Dual (Endo (r -> r))) s t a b -> (i -> a -> r -> r) -> r -> s -> r
- ifoldlOf' :: IndexedGetting i (Endo (r -> r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r
- ifoldrMOf :: Monad m => IndexedGetting i (Dual (Endo (r -> m r))) s t a b -> (i -> a -> r -> m r) -> r -> s -> m r
- ifoldlMOf :: Monad m => IndexedGetting i (Endo (r -> m r)) s t a b -> (i -> r -> a -> m r) -> r -> s -> m r
- itoListOf :: IndexedGetting i (Endo [(i, a)]) s t a b -> s -> [(i, a)]
- withIndicesOf :: Functor f => Overloaded (Indexed i) f s t a b -> LensLike f s t (i, a) (j, b)
- indicesOf :: Gettable f => Overloaded (Indexed i) f s t a a -> LensLike f s t i j
- ifiltering :: (Applicative f, Indexable i k) => (i -> a -> Bool) -> Indexed i (a -> f a) (s -> f t) -> k (a -> f a) (s -> f t)
- ibackwards :: Indexable i k => Indexed i (a -> Backwards f b) (s -> Backwards f t) -> k (a -> f b) (s -> f t)
- itakingWhile :: (Gettable f, Applicative f, Indexable i k) => (i -> a -> Bool) -> IndexedGetting i (Endo (f s)) s s a a -> k (a -> f a) (s -> f s)
- idroppingWhile :: (Gettable f, Applicative f, Indexable i k) => (i -> a -> Bool) -> IndexedGetting i (Endo (f s, f s)) s s a a -> k (a -> f a) (s -> f s)
- newtype ReifiedIndexedFold i s a = ReifyIndexedFold {
- reflectIndexedFold :: IndexedFold i s a
Indexed Folds
type IndexedFold i s a = forall k f. (Indexable i k, Applicative f, Gettable f) => k (a -> f a) (s -> f s)Source
Every IndexedFold is a valid Fold.
Consuming Indexed Folds
ifoldMapOf :: IndexedGetting i m s t a b -> (i -> a -> m) -> s -> mSource
Fold an IndexedFold or IndexedTraversal by mapping indices and values to an arbitrary Monoid with access
to the i.
When you don't need access to the index then foldMapOf is more flexible in what it accepts.
foldMapOfl ≡ifoldMapOfl.const
ifoldMapOf::IndexedGetteri a s -> (i -> s -> m) -> a -> mifoldMapOf::Monoidm =>IndexedFoldi a s -> (i -> s -> m) -> a -> mifoldMapOf::SimpleIndexedLensi a s -> (i -> s -> m) -> a -> mifoldMapOf::Monoidm =>SimpleIndexedTraversali a s -> (i -> s -> m) -> a -> m
ifoldrOf :: IndexedGetting i (Endo r) s t a b -> (i -> a -> r -> r) -> r -> s -> rSource
Right-associative fold of parts of a structure that are viewed through an IndexedFold or IndexedTraversal with
access to the i.
When you don't need access to the index then foldrOf is more flexible in what it accepts.
foldrOfl ≡ifoldrOfl.const
ifoldrOf::IndexedGetteri s a -> (i -> a -> r -> r) -> r -> s -> rifoldrOf::IndexedFoldi s a -> (i -> a -> r -> r) -> r -> s -> rifoldrOf::SimpleIndexedLensi s a -> (i -> a -> r -> r) -> r -> s -> rifoldrOf::SimpleIndexedTraversali s a -> (i -> a -> r -> r) -> r -> s -> r
ifoldlOf :: IndexedGetting i (Dual (Endo r)) s t a b -> (i -> r -> a -> r) -> r -> s -> rSource
Left-associative fold of the parts of a structure that are viewed through an IndexedFold or IndexedTraversal with
access to the i.
When you don't need access to the index then foldlOf is more flexible in what it accepts.
foldlOfl ≡ifoldlOfl.const
ifoldlOf::IndexedGetteri s a -> (i -> r -> a -> r) -> r -> s -> rifoldlOf::IndexedFoldi s a -> (i -> r -> a -> r) -> r -> s -> rifoldlOf::SimpleIndexedLensi s a -> (i -> r -> a -> r) -> r -> s -> rifoldlOf::SimpleIndexedTraversali s a -> (i -> r -> a -> r) -> r -> s -> r
ianyOf :: IndexedGetting i Any s t a b -> (i -> a -> Bool) -> s -> BoolSource
Return whether or not any element viewed through an IndexedFold or IndexedTraversal
satisfy a predicate, with access to the i.
When you don't need access to the index then anyOf is more flexible in what it accepts.
anyOfl ≡ianyOfl.const
ianyOf::IndexedGetteri s a -> (i -> a ->Bool) -> s ->BoolianyOf::IndexedFoldi s a -> (i -> a ->Bool) -> s ->BoolianyOf::SimpleIndexedLensi s a -> (i -> a ->Bool) -> s ->BoolianyOf::SimpleIndexedTraversali s a -> (i -> a ->Bool) -> s ->Bool
iallOf :: IndexedGetting i All s t a b -> (i -> a -> Bool) -> s -> BoolSource
Return whether or not all elements viewed through an IndexedFold or IndexedTraversal
satisfy a predicate, with access to the i.
When you don't need access to the index then allOf is more flexible in what it accepts.
allOfl ≡iallOfl.const
iallOf::IndexedGetteri s a -> (i -> a ->Bool) -> s ->BooliallOf::IndexedFoldi s a -> (i -> a ->Bool) -> s ->BooliallOf::SimpleIndexedLensi s a -> (i -> a ->Bool) -> s ->BooliallOf::SimpleIndexedTraversali s a -> (i -> a ->Bool) -> s ->Bool
itraverseOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> (i -> a -> f r) -> s -> f ()Source
Traverse the targets of an IndexedFold or IndexedTraversal with access to the i, discarding the results.
When you don't need access to the index then traverseOf_ is more flexible in what it accepts.
traverseOf_l ≡itraverseOfl.const
itraverseOf_::Functorf =>IndexedGetteri s a -> (i -> a -> f r) -> s -> f ()itraverseOf_::Applicativef =>IndexedFoldi s a -> (i -> a -> f r) -> s -> f ()itraverseOf_::Functorf =>SimpleIndexedLensi s a -> (i -> a -> f r) -> s -> f ()itraverseOf_::Applicativef =>SimpleIndexedTraversali s a -> (i -> a -> f r) -> s -> f ()
iforOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> s -> (i -> a -> f r) -> f ()Source
Traverse the targets of an IndexedFold or IndexedTraversal with access to the index, discarding the results
(with the arguments flipped).
iforOf_≡flip.itraverseOf_
When you don't need access to the index then forOf_ is more flexible in what it accepts.
forOf_l a ≡iforOf_l a.const
iforOf_::Functorf =>IndexedGetteri s a -> s -> (i -> a -> f r) -> f ()iforOf_::Applicativef =>IndexedFoldi s a -> s -> (i -> a -> f r) -> f ()iforOf_::Functorf =>SimpleIndexedLensi s a -> s -> (i -> a -> f r) -> f ()iforOf_::Applicativef =>SimpleIndexedTraversali s a -> s -> (i -> a -> f r) -> f ()
imapMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> (i -> a -> m r) -> s -> m ()Source
Run monadic actions for each target of an IndexedFold or IndexedTraversal with access to the index,
discarding the results.
When you don't need access to the index then mapMOf_ is more flexible in what it accepts.
mapMOf_l ≡imapMOfl.const
imapMOf_::Monadm =>IndexedGetteri s a -> (i -> a -> m r) -> s -> m ()imapMOf_::Monadm =>IndexedFoldi s a -> (i -> a -> m r) -> s -> m ()imapMOf_::Monadm =>SimpleIndexedLensi s a -> (i -> a -> m r) -> s -> m ()imapMOf_::Monadm =>SimpleIndexedTraversali s a -> (i -> a -> m r) -> s -> m ()
iforMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> s -> (i -> a -> m r) -> m ()Source
Run monadic actions for each target of an IndexedFold or IndexedTraversal with access to the index,
discarding the results (with the arguments flipped).
iforMOf_≡flip.imapMOf_
When you don't need access to the index then forMOf_ is more flexible in what it accepts.
forMOf_l a ≡iforMOfl a.const
iforMOf_::Monadm =>IndexedGetteri s a -> s -> (i -> a -> m r) -> m ()iforMOf_::Monadm =>IndexedFoldi s a -> s -> (i -> a -> m r) -> m ()iforMOf_::Monadm =>SimpleIndexedLensi s a -> s -> (i -> a -> m r) -> m ()iforMOf_::Monadm =>SimpleIndexedTraversali s a -> s -> (i -> a -> m r) -> m ()
iconcatMapOf :: IndexedGetting i [r] s t a b -> (i -> a -> [r]) -> s -> [r]Source
Concatenate the results of a function of the elements of an IndexedFold or IndexedTraversal
with access to the index.
When you don't need access to the index then concatMapOf is more flexible in what it accepts.
concatMapOfl ≡iconcatMapOfl.consticoncatMapOf≡ifoldMapOf
iconcatMapOf::IndexedGetteri s a -> (i -> a -> [r]) -> s -> [r]iconcatMapOf::IndexedFoldi s a -> (i -> a -> [r]) -> s -> [r]iconcatMapOf::SimpleIndexedLensi s a -> (i -> a -> [r]) -> s -> [r]iconcatMapOf::SimpleIndexedTraversali s a -> (i -> a -> [r]) -> s -> [r]
ifindOf :: IndexedGetting i (First (i, a)) s t a b -> (i -> a -> Bool) -> s -> Maybe (i, a)Source
The findOf function takes an IndexedFold or IndexedTraversal, a predicate that is also
supplied the index, a structure and returns the left-most element of the structure
matching the predicate, or Nothing if there is no such element.
When you don't need access to the index then findOf is more flexible in what it accepts.
findOfl ≡ifindOfl.const
ifindOf::IndexedGetters a -> (i -> a ->Bool) -> s ->Maybe(i, a)ifindOf::IndexedFolds a -> (i -> a ->Bool) -> s ->Maybe(i, a)ifindOf::SimpleIndexedLenss a -> (i -> a ->Bool) -> s ->Maybe(i, a)ifindOf::SimpleIndexedTraversals a -> (i -> a ->Bool) -> s ->Maybe(i, a)
ifoldrOf' :: IndexedGetting i (Dual (Endo (r -> r))) s t a b -> (i -> a -> r -> r) -> r -> s -> rSource
Strictly fold right over the elements of a structure with an index.
When you don't need access to the index then foldrOf' is more flexible in what it accepts.
foldrOf'l ≡ifoldrOf'l.const
ifoldrOf'::IndexedGetteri s a -> (i -> a -> r -> r) -> r -> s -> rifoldrOf'::IndexedFoldi s a -> (i -> a -> r -> r) -> r -> s -> rifoldrOf'::SimpleIndexedLensi s a -> (i -> a -> r -> r) -> r -> s -> rifoldrOf'::SimpleIndexedTraversali s a -> (i -> a -> r -> r) -> r -> s -> r
ifoldlOf' :: IndexedGetting i (Endo (r -> r)) s t a b -> (i -> r -> a -> r) -> r -> s -> rSource
Fold over the elements of a structure with an index, associating to the left, but strictly.
When you don't need access to the index then foldlOf' is more flexible in what it accepts.
foldlOf'l ≡ifoldlOf'l.const
ifoldlOf'::IndexedGetteri s a -> (i -> r -> a -> r) -> r -> s -> rifoldlOf'::IndexedFoldi s a -> (i -> r -> a -> r) -> r -> s -> rifoldlOf'::SimpleIndexedLensi s a -> (i -> r -> a -> r) -> r -> s -> rifoldlOf'::SimpleIndexedTraversali s a -> (i -> r -> a -> r) -> r -> s -> r
ifoldrMOf :: Monad m => IndexedGetting i (Dual (Endo (r -> m r))) s t a b -> (i -> a -> r -> m r) -> r -> s -> m rSource
Monadic fold right over the elements of a structure with an index.
When you don't need access to the index then foldrMOf is more flexible in what it accepts.
foldrMOfl ≡ifoldrMOfl.const
ifoldrMOf::Monadm =>IndexedGetteri s a -> (i -> a -> r -> m r) -> r -> s -> rifoldrMOf::Monadm =>IndexedFoldi s a -> (i -> a -> r -> m r) -> r -> s -> rifoldrMOf::Monadm =>SimpleIndexedLensi s a -> (i -> a -> r -> m r) -> r -> s -> rifoldrMOf::Monadm =>SimpleIndexedTraversali s a -> (i -> a -> r -> m r) -> r -> s -> r
ifoldlMOf :: Monad m => IndexedGetting i (Endo (r -> m r)) s t a b -> (i -> r -> a -> m r) -> r -> s -> m rSource
Monadic fold over the elements of a structure with an index, associating to the left.
When you don't need access to the index then foldlMOf is more flexible in what it accepts.
foldlMOfl ≡ifoldlMOfl.const
ifoldlOf'::Monadm =>IndexedGetteri s a -> (i -> r -> a -> m r) -> r -> s -> rifoldlOf'::Monadm =>IndexedFoldi s a -> (i -> r -> a -> m r) -> r -> s -> rifoldlOf'::Monadm =>SimpleIndexedLensi s a -> (i -> r -> a -> m r) -> r -> s -> rifoldlOf'::Monadm =>SimpleIndexedTraversali s a -> (i -> r -> a -> m r) -> r -> s -> r
itoListOf :: IndexedGetting i (Endo [(i, a)]) s t a b -> s -> [(i, a)]Source
Extract the key-value pairs from a structure.
When you don't need access to the indices in the result, then toListOf is more flexible in what it accepts.
toListOfl ≡mapfst.itoListOfl
itoListOf::IndexedGetteri s a -> s -> [(i,a)]itoListOf::IndexedFoldi s a -> s -> [(i,a)]itoListOf::SimpleIndexedLensi s a -> s -> [(i,a)]itoListOf::SimpleIndexedTraversali s a -> s -> [(i,a)]
Converting to Folds
withIndicesOf :: Functor f => Overloaded (Indexed i) f s t a b -> LensLike f s t (i, a) (j, b)Source
Transform an indexed fold into a fold of both the indices and the values.
withIndicesOf::IndexedFoldi s a ->Folds (i, a)withIndicesOf::SimpleIndexedLensi s a ->Getters (i, a)withIndicesOf::SimpleIndexedTraversali s a ->Folds (i, a)
All Fold operations are safe, and comply with the laws. However:
Passing this an IndexedTraversal will still allow many
Traversal combinators to type check on the result, but the result
can only be legally traversed by operations that do not edit the indices.
withIndicesOf::IndexedTraversali s t a b ->Traversals t (i, a) (j, b)
Change made to the indices will be discarded.
indicesOf :: Gettable f => Overloaded (Indexed i) f s t a a -> LensLike f s t i jSource
Transform an indexed fold into a fold of the indices.
indicesOf::IndexedFoldi s a ->Folds iindicesOf::SimpleIndexedLensi s a ->Getters iindicesOf::SimpleIndexedTraversali s a ->Folds i
Building Indexed Folds
ifiltering :: (Applicative f, Indexable i k) => (i -> a -> Bool) -> Indexed i (a -> f a) (s -> f t) -> k (a -> f a) (s -> f t)Source
Obtain an IndexedFold by filtering an IndexedLens, IndexedGetter, or IndexedFold.
When passed an IndexedTraversal, sadly the result is not a legal IndexedTraversal.
See filtered for a related counter-example.
ibackwards :: Indexable i k => Indexed i (a -> Backwards f b) (s -> Backwards f t) -> k (a -> f b) (s -> f t)Source
Reverse the order of the elements of an IndexedFold or
IndexedTraversal.
This has no effect on an IndexedLens,
IndexedGetter, or IndexedSetter.
itakingWhile :: (Gettable f, Applicative f, Indexable i k) => (i -> a -> Bool) -> IndexedGetting i (Endo (f s)) s s a a -> k (a -> f a) (s -> f s)Source
Obtain an IndexedFold by taking elements from another
IndexedFold, IndexedLens,
IndexedGetter or IndexedTraversal
while a predicate holds.
idroppingWhile :: (Gettable f, Applicative f, Indexable i k) => (i -> a -> Bool) -> IndexedGetting i (Endo (f s, f s)) s s a a -> k (a -> f a) (s -> f s)Source
Obtain an IndexedFold by dropping elements from another IndexedFold, IndexedLens, IndexedGetter or IndexedTraversal while a predicate holds.
Storing Indexed Folds
newtype ReifiedIndexedFold i s a Source
Useful for storage.
Constructors
| ReifyIndexedFold | |
Fields
| |