| Portability | rank 2 types, MPTCs, TFs, flexible |
|---|---|
| Stability | provisional |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Safe Haskell | None |
Control.Lens.IndexedTraversal
Contents
Description
- type IndexedTraversal i a b c d = forall f k. (Indexed i k, Applicative f) => k (c -> f d) (a -> f b)
- traverseAt :: At k m => k -> SimpleIndexedTraversal k (m v) v
- iwhereOf :: (Indexed i k, Applicative f) => Overloaded (Index i) f a b c c -> (i -> Bool) -> Overloaded k f a b c c
- value :: (k -> Bool) -> SimpleIndexedTraversal k (k, v) v
- class Ord k => TraverseMin k m | m -> k where
- traverseMin :: SimpleIndexedTraversal k (m v) v
- class Ord k => TraverseMax k m | m -> k where
- traverseMax :: SimpleIndexedTraversal k (m v) v
- itraverseOf :: Overloaded (Index i) f a b c d -> (i -> c -> f d) -> a -> f b
- iforOf :: Overloaded (Index i) f a b c d -> a -> (i -> c -> f d) -> f b
- imapMOf :: Overloaded (Index i) (WrappedMonad m) a b c d -> (i -> c -> m d) -> a -> m b
- iforMOf :: Overloaded (Index i) (WrappedMonad m) a b c d -> a -> (i -> c -> m d) -> m b
- imapAccumROf :: Overloaded (Index i) (State s) a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)
- imapAccumLOf :: Overloaded (Index i) (Backwards (State s)) a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)
- newtype ReifiedIndexedTraversal i a b c d = ReifyIndexedTraversal {
- reflectIndexedTraversal :: IndexedTraversal i a b c d
- type SimpleIndexedTraversal i a b = IndexedTraversal i a a b b
- type SimpleReifiedIndexedTraversal i a b = ReifiedIndexedTraversal i a a b b
Indexed Traversals
type IndexedTraversal i a b c d = forall f k. (Indexed i k, Applicative f) => k (c -> f d) (a -> f b)Source
Every indexed traversal is a valid Traversal or IndexedFold.
The Indexed constraint is used to allow an IndexedTraversal to be used directly as a Traversal.
The Traversal laws are still required to hold.
Common Indexed Traversals
traverseAt :: At k m => k -> SimpleIndexedTraversal k (m v) vSource
Traverse the value at a given key in a map
traverseAtk =atk<.traverse
iwhereOf :: (Indexed i k, Applicative f) => Overloaded (Index i) f a b c c -> (i -> Bool) -> Overloaded k f a b c cSource
Access the element of an IndexedTraversal where the index matches a predicate.
>>>:m + Control.Lens>>>over (iwhereOf (indexed traverse) (>0)) reverse $ ["He","was","stressed","o_O"]["He","saw","desserts","O_o"]
iwhereOf::IndexedFoldi a b -> (i ->Bool) ->IndexedFoldi a biwhereOf::IndexedGetteri a b -> (i ->Bool) ->IndexedFoldi a biwhereOf::SimpleIndexedLensi a b -> (i ->Bool) ->SimpleIndexedTraversali a biwhereOf::SimpleIndexedTraversali a b -> (i ->Bool) ->SimpleIndexedTraversali a biwhereOf::SimpleIndexedSetteri a b -> (i ->Bool) ->SimpleIndexedSetteri a b
value :: (k -> Bool) -> SimpleIndexedTraversal k (k, v) vSource
This provides a Traversal that checks a predicate on a key before
allowing you to traverse into a value.
class Ord k => TraverseMin k m | m -> k whereSource
Allows IndexedTraversal the value at the smallest index.
Methods
traverseMin :: SimpleIndexedTraversal k (m v) vSource
IndexedTraversal of the element with the smallest index.
Instances
| TraverseMin Int IntMap | |
| Ord k => TraverseMin k (Map k) |
class Ord k => TraverseMax k m | m -> k whereSource
Allows IndexedTraversal of the value at the largest index.
Methods
traverseMax :: SimpleIndexedTraversal k (m v) vSource
IndexedTraversal of the element at the largest index.
Instances
| TraverseMax Int IntMap | |
| Ord k => TraverseMax k (Map k) |
Indexed Traversal Combinators
itraverseOf :: Overloaded (Index i) f a b c d -> (i -> c -> f d) -> a -> f bSource
Traversal with an index.
NB: When you don't need access to the index then you can just apply your IndexedTraversal
directly as a function!
itraverseOf≡withIndextraverseOfl =itraverseOfl.const=id
itraverseOf::IndexedLensi a b c d -> (i -> c -> f d) -> a -> f bitraverseOf::IndexedTraversali a b c d -> (i -> c -> f d) -> a -> f b
iforOf :: Overloaded (Index i) f a b c d -> a -> (i -> c -> f d) -> f bSource
Traverse with an index (and the arguments flipped)
forOfl a ≡iforOfl a.constiforOf≡flip.itraverseOf
iforOf::IndexedLensi a b c d -> a -> (i -> c -> f d) -> f biforOf::IndexedTraversali a b c d -> a -> (i -> c -> f d) -> f b
imapMOf :: Overloaded (Index i) (WrappedMonad m) a b c d -> (i -> c -> m d) -> a -> m bSource
Map each element of a structure targeted by a lens to a monadic action, evaluate these actions from left to right, and collect the results, with access its position.
When you don't need access to the index mapMOf is more liberal in what it can accept.
mapMOfl ≡imapMOfl.const
imapMOf::Monadm =>IndexedLensi a b c d -> (i -> c -> m d) -> a -> m bimapMOf::Monadm =>IndexedTraversali a b c d -> (i -> c -> m d) -> a -> m b
iforMOf :: Overloaded (Index i) (WrappedMonad m) a b c d -> a -> (i -> c -> m d) -> m bSource
Map each element of a structure targeted by a lens to a monadic action, evaluate these actions from left to right, and collect the results, with access its position (and the arguments flipped).
forMOfl a ≡iforMOfl a.constiforMOf≡flip.imapMOf
iforMOf::Monadm =>IndexedLensi a b c d -> a -> (i -> c -> m d) -> m biforMOf::Monadm =>IndexedTraversali a b c d -> a -> (i -> c -> m d) -> m b
imapAccumROf :: Overloaded (Index i) (State s) a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)Source
Generalizes mapAccumR to an arbitrary IndexedTraversal with access to the index.
imapAccumROf accumulates state from right to left.
mapAccumROfl ≡imapAccumROfl.const
imapAccumROf::IndexedLensi a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)imapAccumROf::IndexedTraversali a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)
imapAccumLOf :: Overloaded (Index i) (Backwards (State s)) a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)Source
Generalizes mapAccumL to an arbitrary IndexedTraversal with access to the index.
imapAccumLOf accumulates state from left to right.
mapAccumLOfl ≡imapAccumLOfl.const
imapAccumLOf::IndexedLensi a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)imapAccumLOf::IndexedTraversali a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)
Storing Indexed Traversals
newtype ReifiedIndexedTraversal i a b c d Source
Useful for storage.
Constructors
| ReifyIndexedTraversal | |
Fields
| |
Simple
type SimpleIndexedTraversal i a b = IndexedTraversal i a a b bSource
typeSimpleIndexedTraversali =Simple(IndexedTraversali)
type SimpleReifiedIndexedTraversal i a b = ReifiedIndexedTraversal i a a b bSource
typeSimpleIndexedTraversali =Simple(ReifiedIndexedTraversali)