| Copyright | (C) 2012-16 Edward Kmett |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | provisional |
| Portability | Rank2Types |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Control.Lens.Indexed
Description
(The classes in here need to be defined together for DefaultSignatures to work.)
Synopsis
- class Conjoined p => Indexable i (p :: Type -> Type -> Type) where
- indexed :: p a b -> i -> a -> b
- class (Choice p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Strong p, Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), Costrong p, ArrowLoop p, ArrowApply p, ArrowChoice p, Closed p) => Conjoined (p :: Type -> Type -> Type) where
- newtype Indexed i a b = Indexed {
- runIndexed :: i -> a -> b
- (<.) :: Indexable i p => (Indexed i s t -> r) -> ((a -> b) -> s -> t) -> p a b -> r
- (<.>) :: Indexable (i, j) p => (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> p a b -> r
- (.>) :: (st -> r) -> (kab -> st) -> kab -> r
- selfIndex :: Indexable a p => p a fb -> a -> fb
- reindexed :: Indexable j p => (i -> j) -> (Indexed i a b -> r) -> p a b -> r
- icompose :: Indexable p c => (i -> j -> p) -> (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> c a b -> r
- indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
- indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t
- class Functor f => FunctorWithIndex i (f :: Type -> Type) | f -> i where
- imap :: (i -> a -> b) -> f a -> f b
- imapped :: forall i (f :: Type -> Type) a b. FunctorWithIndex i f => IndexedSetter i (f a) (f b) a b
- class Foldable f => FoldableWithIndex i (f :: Type -> Type) | f -> i where
- ifolded :: forall i (f :: Type -> Type) a. FoldableWithIndex i f => IndexedFold i (f a) a
- iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- inone :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- none :: Foldable f => (a -> Bool) -> f a -> Bool
- itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f ()
- ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f ()
- imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m ()
- iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m ()
- iconcatMap :: FoldableWithIndex i f => (i -> a -> [b]) -> f a -> [b]
- ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a)
- ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b
- ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b
- itoList :: FoldableWithIndex i f => f a -> [(i, a)]
- withIndex :: (Indexable i p, Functor f) => p (i, s) (f (j, t)) -> Indexed i s (f t)
- asIndex :: (Indexable i p, Contravariant f, Functor f) => p i (f i) -> Indexed i s (f s)
- indices :: (Indexable i p, Applicative f) => (i -> Bool) -> Optical' p (Indexed i) f a a
- index :: (Indexable i p, Eq i, Applicative f) => i -> Optical' p (Indexed i) f a a
- class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i (t :: Type -> Type) | t -> i where
- itraverse :: Applicative f => (i -> a -> f b) -> t a -> f (t b)
- itraversed :: forall i (t :: Type -> Type) a b. TraversableWithIndex i t => IndexedTraversal i (t a) (t b) a b
- ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b)
- imapM :: (TraversableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m (t b)
- iforM :: (TraversableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m (t b)
- imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
- imapAccumL :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
- ifoldMapBy :: FoldableWithIndex i t => (r -> r -> r) -> r -> (i -> a -> r) -> t a -> r
- ifoldMapByOf :: IndexedFold i t a -> (r -> r -> r) -> r -> (i -> a -> r) -> t -> r
- itraverseBy :: TraversableWithIndex i t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (i -> a -> f b) -> t a -> f (t b)
- itraverseByOf :: IndexedTraversal i s t a b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (i -> a -> f b) -> s -> f t
Indexing
class Conjoined p => Indexable i (p :: Type -> Type -> Type) where #
This class permits overloading of function application for things that also admit a notion of a key or index.
class (Choice p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Strong p, Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), Costrong p, ArrowLoop p, ArrowApply p, ArrowChoice p, Closed p) => Conjoined (p :: Type -> Type -> Type) where #
This is a Profunctor that is both Corepresentable by f and Representable by g such
that f is left adjoint to g. From this you can derive a lot of structure due
to the preservation of limits and colimits.
Minimal complete definition
Nothing
Methods
distrib :: Functor f => p a b -> p (f a) (f b) #
Conjoined is strong enough to let us distribute every Conjoined
Profunctor over every Haskell Functor. This is effectively a
generalization of fmap.
conjoined :: (p ~ (->) => q (a -> b) r) -> q (p a b) r -> q (p a b) r #
This permits us to make a decision at an outermost point about whether or not we use an index.
Ideally any use of this function should be done in such a way so that you compute the same answer, but this cannot be enforced at the type level.
Instances
| Conjoined ReifiedGetter # | |
Defined in Control.Lens.Reified Methods distrib :: Functor f => ReifiedGetter a b -> ReifiedGetter (f a) (f b) # conjoined :: (ReifiedGetter ~ (->) => q (a -> b) r) -> q (ReifiedGetter a b) r -> q (ReifiedGetter a b) r # | |
| Conjoined (Indexed i) # | |
| Conjoined (->) # | |
A function with access to a index. This constructor may be useful when you need to store
an Indexable in a container to avoid ImpredicativeTypes.
index :: Indexed i a b -> i -> a -> b
Constructors
| Indexed | |
Fields
| |
Instances
(<.) :: Indexable i p => (Indexed i s t -> r) -> ((a -> b) -> s -> t) -> p a b -> r infixr 9 #
Compose an Indexed function with a non-indexed function.
Mnemonically, the < points to the indexing we want to preserve.
>>>let nestedMap = (fmap Map.fromList . Map.fromList) [(1, [(10, "one,ten"), (20, "one,twenty")]), (2, [(30, "two,thirty"), (40,"two,forty")])]>>>nestedMap^..(itraversed<.itraversed).withIndex[(1,"one,ten"),(1,"one,twenty"),(2,"two,thirty"),(2,"two,forty")]
(<.>) :: Indexable (i, j) p => (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> p a b -> r infixr 9 #
Composition of Indexed functions.
Mnemonically, the < and > points to the fact that we want to preserve the indices.
>>>let nestedMap = (fmap Map.fromList . Map.fromList) [(1, [(10, "one,ten"), (20, "one,twenty")]), (2, [(30, "two,thirty"), (40,"two,forty")])]>>>nestedMap^..(itraversed<.>itraversed).withIndex[((1,10),"one,ten"),((1,20),"one,twenty"),((2,30),"two,thirty"),((2,40),"two,forty")]
(.>) :: (st -> r) -> (kab -> st) -> kab -> r infixr 9 #
Compose a non-indexed function with an Indexed function.
Mnemonically, the > points to the indexing we want to preserve.
This is the same as (..)
f (and . gf ) gives you the index of .> gg unless g is index-preserving, like a
Prism, Iso or Equality, in which case it'll pass through the index of f.
>>>let nestedMap = (fmap Map.fromList . Map.fromList) [(1, [(10, "one,ten"), (20, "one,twenty")]), (2, [(30, "two,thirty"), (40,"two,forty")])]>>>nestedMap^..(itraversed.>itraversed).withIndex[(10,"one,ten"),(20,"one,twenty"),(30,"two,thirty"),(40,"two,forty")]
selfIndex :: Indexable a p => p a fb -> a -> fb #
Use a value itself as its own index. This is essentially an indexed version of id.
Note: When used to modify the value, this can break the index requirements assumed by indices and similar,
so this is only properly an IndexedGetter, but it can be used as more.
selfIndex::IndexedGettera a b
icompose :: Indexable p c => (i -> j -> p) -> (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> c a b -> r #
Composition of Indexed functions with a user supplied function for combining indices.
indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t #
Transform a Traversal into an IndexedTraversal or
a Fold into an IndexedFold, etc.
indexing::Traversals t a b ->IndexedTraversalInts t a bindexing::Prisms t a b ->IndexedTraversalInts t a bindexing::Lenss t a b ->IndexedLensInts t a bindexing::Isos t a b ->IndexedLensInts t a bindexing::Folds a ->IndexedFoldInts aindexing::Getters a ->IndexedGetterInts a
indexing::IndexableIntp =>LensLike(Indexingf) s t a b ->Overp f s t a b
indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t #
Transform a Traversal into an IndexedTraversal or
a Fold into an IndexedFold, etc.
This combinator is like indexing except that it handles large traversals and folds gracefully.
indexing64::Traversals t a b ->IndexedTraversalInt64s t a bindexing64::Prisms t a b ->IndexedTraversalInt64s t a bindexing64::Lenss t a b ->IndexedLensInt64s t a bindexing64::Isos t a b ->IndexedLensInt64s t a bindexing64::Folds a ->IndexedFoldInt64s aindexing64::Getters a ->IndexedGetterInt64s a
indexing64::IndexableInt64p =>LensLike(Indexing64f) s t a b ->Overp f s t a b
Indexed Functors
class Functor f => FunctorWithIndex i (f :: Type -> Type) | f -> i where #
A Functor with an additional index.
Instances must satisfy a modified form of the Functor laws:
imapf.imapg ≡imap(\i -> f i.g i)imap(\_ a -> a) ≡id
Minimal complete definition
Nothing
Methods
imap :: (i -> a -> b) -> f a -> f b #
Map with access to the index.
default imap :: TraversableWithIndex i f => (i -> a -> b) -> f a -> f b #
Instances
| FunctorWithIndex () Identity | |
| FunctorWithIndex () Par1 | |
| FunctorWithIndex () Maybe | |
| FunctorWithIndex Int IntMap | |
| FunctorWithIndex Int Seq | The position in the |
| FunctorWithIndex Int NonEmpty | |
| FunctorWithIndex Int ZipList | Same instance as for |
| FunctorWithIndex Int Deque # | |
| FunctorWithIndex Int [] | The position in the list is available as the index. |
| FunctorWithIndex Void (Proxy :: Type -> Type) | |
| FunctorWithIndex Void (U1 :: Type -> Type) | |
| FunctorWithIndex Void (V1 :: Type -> Type) | |
| Ix i => FunctorWithIndex i (Array i) | |
| FunctorWithIndex i (Level i) # | |
Defined in Control.Lens.Internal.Level | |
| FunctorWithIndex k (Map k) | |
| FunctorWithIndex k ((,) k) | |
| FunctorWithIndex Void (Const e :: Type -> Type) | |
| FunctorWithIndex Void (Constant e :: Type -> Type) | |
| FunctorWithIndex i f => FunctorWithIndex i (Rec1 f) | |
| FunctorWithIndex i f => FunctorWithIndex i (Backwards f) | |
| FunctorWithIndex i m => FunctorWithIndex i (IdentityT m) | |
| FunctorWithIndex i f => FunctorWithIndex i (Reverse f) | |
| FunctorWithIndex Void (K1 i c :: Type -> Type) | |
| FunctorWithIndex i (Magma i t b) # | |
Defined in Control.Lens.Internal.Magma | |
| FunctorWithIndex r ((->) r) | |
| FunctorWithIndex [Int] Tree | |
| FunctorWithIndex i f => FunctorWithIndex [i] (Cofree f) | |
Defined in Control.Comonad.Cofree | |
| FunctorWithIndex i f => FunctorWithIndex [i] (Free f) | |
Defined in Control.Monad.Free | |
| FunctorWithIndex i m => FunctorWithIndex (e, i) (ReaderT e m) | |
| FunctorWithIndex i w => FunctorWithIndex (s, i) (TracedT s w) | |
Defined in Control.Comonad.Trans.Traced | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Product f g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Sum f g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (f :*: g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (f :+: g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (i, j) (Compose f g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (i, j) (f :.: g) | |
Indexed Functor Combinators
imapped :: forall i (f :: Type -> Type) a b. FunctorWithIndex i f => IndexedSetter i (f a) (f b) a b #
The IndexedSetter for a FunctorWithIndex.
If you don't need access to the index, then mapped is more flexible in what it accepts.
Indexed Foldables
class Foldable f => FoldableWithIndex i (f :: Type -> Type) | f -> i where #
A container that supports folding with an additional index.
Minimal complete definition
Nothing
Methods
ifoldMap :: Monoid m => (i -> a -> m) -> f a -> m #
Fold a container by mapping value to an arbitrary Monoid with access to the index i.
When you don't need access to the index then foldMap is more flexible in what it accepts.
foldMap≡ifoldMap.const
default ifoldMap :: (TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m #
ifoldMap' :: Monoid m => (i -> a -> m) -> f a -> m #
A variant of ifoldMap that is strict in the accumulator.
When you don't need access to the index then foldMap' is more flexible in what it accepts.
foldMap'≡ifoldMap'.const
ifoldr :: (i -> a -> b -> b) -> b -> f a -> b #
Right-associative fold of an indexed container with access to the index i.
When you don't need access to the index then foldr is more flexible in what it accepts.
foldr≡ifoldr.const
ifoldl :: (i -> b -> a -> b) -> b -> f a -> b #
Left-associative fold of an indexed container with access to the index i.
When you don't need access to the index then foldl is more flexible in what it accepts.
foldl≡ifoldl.const
Instances
| FoldableWithIndex () Identity | |
Defined in WithIndex | |
| FoldableWithIndex () Par1 | |
| FoldableWithIndex () Maybe | |
| FoldableWithIndex Int IntMap | |
Defined in WithIndex | |
| FoldableWithIndex Int Seq | |
| FoldableWithIndex Int NonEmpty | |
Defined in WithIndex | |
| FoldableWithIndex Int ZipList | |
Defined in WithIndex | |
| FoldableWithIndex Int Deque # | |
Defined in Control.Lens.Internal.Deque | |
| FoldableWithIndex Int [] | |
| FoldableWithIndex Void (Proxy :: Type -> Type) | |
Defined in WithIndex | |
| FoldableWithIndex Void (U1 :: Type -> Type) | |
| FoldableWithIndex Void (V1 :: Type -> Type) | |
| Ix i => FoldableWithIndex i (Array i) | |
Defined in WithIndex | |
| FoldableWithIndex i (Level i) # | |
Defined in Control.Lens.Internal.Level | |
| FoldableWithIndex k (Map k) | |
| FoldableWithIndex k ((,) k) | |
| FoldableWithIndex Void (Const e :: Type -> Type) | |
Defined in WithIndex | |
| FoldableWithIndex Void (Constant e :: Type -> Type) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Void -> a -> m) -> Constant e a -> m # ifoldMap' :: Monoid m => (Void -> a -> m) -> Constant e a -> m # ifoldr :: (Void -> a -> b -> b) -> b -> Constant e a -> b # ifoldl :: (Void -> b -> a -> b) -> b -> Constant e a -> b # ifoldr' :: (Void -> a -> b -> b) -> b -> Constant e a -> b # ifoldl' :: (Void -> b -> a -> b) -> b -> Constant e a -> b # | |
| FoldableWithIndex i f => FoldableWithIndex i (Rec1 f) | |
| FoldableWithIndex i f => FoldableWithIndex i (Backwards f) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (i -> a -> m) -> Backwards f a -> m # ifoldMap' :: Monoid m => (i -> a -> m) -> Backwards f a -> m # ifoldr :: (i -> a -> b -> b) -> b -> Backwards f a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Backwards f a -> b # | |
| FoldableWithIndex i m => FoldableWithIndex i (IdentityT m) | |
Defined in WithIndex Methods ifoldMap :: Monoid m0 => (i -> a -> m0) -> IdentityT m a -> m0 # ifoldMap' :: Monoid m0 => (i -> a -> m0) -> IdentityT m a -> m0 # ifoldr :: (i -> a -> b -> b) -> b -> IdentityT m a -> b # ifoldl :: (i -> b -> a -> b) -> b -> IdentityT m a -> b # | |
| FoldableWithIndex i f => FoldableWithIndex i (Reverse f) | |
Defined in WithIndex | |
| FoldableWithIndex Void (K1 i c :: Type -> Type) | |
Defined in WithIndex | |
| FoldableWithIndex i (Magma i t b) # | |
Defined in Control.Lens.Internal.Magma Methods ifoldMap :: Monoid m => (i -> a -> m) -> Magma i t b a -> m # ifoldMap' :: Monoid m => (i -> a -> m) -> Magma i t b a -> m # ifoldr :: (i -> a -> b0 -> b0) -> b0 -> Magma i t b a -> b0 # ifoldl :: (i -> b0 -> a -> b0) -> b0 -> Magma i t b a -> b0 # ifoldr' :: (i -> a -> b0 -> b0) -> b0 -> Magma i t b a -> b0 # ifoldl' :: (i -> b0 -> a -> b0) -> b0 -> Magma i t b a -> b0 # | |
| FoldableWithIndex [Int] Tree | |
Defined in WithIndex | |
| FoldableWithIndex i f => FoldableWithIndex [i] (Cofree f) | |
Defined in Control.Comonad.Cofree | |
| FoldableWithIndex i f => FoldableWithIndex [i] (Free f) | |
Defined in Control.Monad.Free | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Product f g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Product f g a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> Product f g a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Sum f g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Sum f g a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> Sum f g a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :*: g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :+: g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (i, j) (Compose f g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => ((i, j) -> a -> m) -> Compose f g a -> m # ifoldMap' :: Monoid m => ((i, j) -> a -> m) -> Compose f g a -> m # ifoldr :: ((i, j) -> a -> b -> b) -> b -> Compose f g a -> b # ifoldl :: ((i, j) -> b -> a -> b) -> b -> Compose f g a -> b # ifoldr' :: ((i, j) -> a -> b -> b) -> b -> Compose f g a -> b # ifoldl' :: ((i, j) -> b -> a -> b) -> b -> Compose f g a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (i, j) (f :.: g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => ((i, j) -> a -> m) -> (f :.: g) a -> m # ifoldMap' :: Monoid m => ((i, j) -> a -> m) -> (f :.: g) a -> m # ifoldr :: ((i, j) -> a -> b -> b) -> b -> (f :.: g) a -> b # ifoldl :: ((i, j) -> b -> a -> b) -> b -> (f :.: g) a -> b # ifoldr' :: ((i, j) -> a -> b -> b) -> b -> (f :.: g) a -> b # ifoldl' :: ((i, j) -> b -> a -> b) -> b -> (f :.: g) a -> b # | |
Indexed Foldable Combinators
ifolded :: forall i (f :: Type -> Type) a. FoldableWithIndex i f => IndexedFold i (f a) a #
The IndexedFold of a FoldableWithIndex container.
is a fold over the keys of a ifolded . asIndexFoldableWithIndex.
>>>Data.Map.fromList [(2, "hello"), (1, "world")]^..ifolded.asIndex[1,2]
iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool #
iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool #
inone :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool #
itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f () #
ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f () #
Traverse elements with access to the index i, discarding the results (with the arguments flipped).
ifor_≡flipitraverse_
When you don't need access to the index then for_ is more flexible in what it accepts.
for_a ≡ifor_a.const
imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m () #
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.
mapM_≡imapM.const
iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m () #
iconcatMap :: FoldableWithIndex i f => (i -> a -> [b]) -> f a -> [b] #
Concatenate the results of a function of the elements of an indexed container with access to the index.
When you don't need access to the index then concatMap is more flexible in what it accepts.
concatMap≡iconcatMap.consticoncatMap≡ifoldMap
ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a) #
ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b #
ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b #
itoList :: FoldableWithIndex i f => f a -> [(i, a)] #
Converting to Folds
withIndex :: (Indexable i p, Functor f) => p (i, s) (f (j, t)) -> Indexed i s (f t) #
Fold a container with indices returning both the indices and the values.
The result is only valid to compose in a Traversal, if you don't edit the
index as edits to the index have no effect.
>>>[10, 20, 30] ^.. ifolded . withIndex[(0,10),(1,20),(2,30)]
>>>[10, 20, 30] ^.. ifolded . withIndex . alongside negated (re _Show)[(0,"10"),(-1,"20"),(-2,"30")]
asIndex :: (Indexable i p, Contravariant f, Functor f) => p i (f i) -> Indexed i s (f s) #
When composed with an IndexedFold or IndexedTraversal this yields an
(Indexed) Fold of the indices.
Restricting by Index
indices :: (Indexable i p, Applicative f) => (i -> Bool) -> Optical' p (Indexed i) f a a #
This allows you to filter an IndexedFold, IndexedGetter, IndexedTraversal or IndexedLens based on a predicate
on the indices.
>>>["hello","the","world","!!!"]^..traversed.indices even["hello","world"]
>>>over (traversed.indices (>0)) Prelude.reverse $ ["He","was","stressed","o_O"]["He","saw","desserts","O_o"]
index :: (Indexable i p, Eq i, Applicative f) => i -> Optical' p (Indexed i) f a a #
This allows you to filter an IndexedFold, IndexedGetter, IndexedTraversal or IndexedLens based on an index.
>>>["hello","the","world","!!!"]^?traversed.index 2Just "world"
Indexed Traversables
class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i (t :: Type -> Type) | t -> i where #
A Traversable with an additional index.
An instance must satisfy a (modified) form of the Traversable laws:
itraverse(constIdentity) ≡Identityfmap(itraversef).itraverseg ≡getCompose.itraverse(\i ->Compose.fmap(f i).g i)
Minimal complete definition
Nothing
Methods
itraverse :: Applicative f => (i -> a -> f b) -> t a -> f (t b) #
Traverse an indexed container.
itraverse≡itraverseOfitraversed
default itraverse :: (i ~ Int, Applicative f) => (i -> a -> f b) -> t a -> f (t b) #
Instances
| TraversableWithIndex () Identity | |
| TraversableWithIndex () Par1 | |
| TraversableWithIndex () Maybe | |
| TraversableWithIndex Int IntMap | |
| TraversableWithIndex Int Seq | |
| TraversableWithIndex Int NonEmpty | |
| TraversableWithIndex Int ZipList | |
| TraversableWithIndex Int Deque # | |
Defined in Control.Lens.Internal.Deque | |
| TraversableWithIndex Int [] | |
Defined in WithIndex Methods itraverse :: Applicative f => (Int -> a -> f b) -> [a] -> f [b] # | |
| TraversableWithIndex Void (Proxy :: Type -> Type) | |
| TraversableWithIndex Void (U1 :: Type -> Type) | |
| TraversableWithIndex Void (V1 :: Type -> Type) | |
| Ix i => TraversableWithIndex i (Array i) | |
| TraversableWithIndex i (Level i) # | |
Defined in Control.Lens.Internal.Level Methods itraverse :: Applicative f => (i -> a -> f b) -> Level i a -> f (Level i b) # | |
| TraversableWithIndex k (Map k) | |
| TraversableWithIndex k ((,) k) | |
Defined in WithIndex Methods itraverse :: Applicative f => (k -> a -> f b) -> (k, a) -> f (k, b) # | |
| TraversableWithIndex Void (Const e :: Type -> Type) | |
| TraversableWithIndex Void (Constant e :: Type -> Type) | |
| TraversableWithIndex i f => TraversableWithIndex i (Rec1 f) | |
| TraversableWithIndex i f => TraversableWithIndex i (Backwards f) | |
| TraversableWithIndex i m => TraversableWithIndex i (IdentityT m) | |
| TraversableWithIndex i f => TraversableWithIndex i (Reverse f) | |
| TraversableWithIndex Void (K1 i c :: Type -> Type) | |
| TraversableWithIndex i (Magma i t b) # | |
Defined in Control.Lens.Internal.Magma Methods itraverse :: Applicative f => (i -> a -> f b0) -> Magma i t b a -> f (Magma i t b b0) # | |
| TraversableWithIndex [Int] Tree | |
| TraversableWithIndex i f => TraversableWithIndex [i] (Cofree f) | |
Defined in Control.Comonad.Cofree Methods itraverse :: Applicative f0 => ([i] -> a -> f0 b) -> Cofree f a -> f0 (Cofree f b) # | |
| TraversableWithIndex i f => TraversableWithIndex [i] (Free f) | |
Defined in Control.Monad.Free Methods itraverse :: Applicative f0 => ([i] -> a -> f0 b) -> Free f a -> f0 (Free f b) # | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Product f g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Sum f g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :*: g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :+: g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (i, j) (Compose f g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (i, j) (f :.: g) | |
Indexed Traversable Combinators
itraversed :: forall i (t :: Type -> Type) a b. TraversableWithIndex i t => IndexedTraversal i (t a) (t b) a b #
The IndexedTraversal of a TraversableWithIndex container.
ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b) #
imapM :: (TraversableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m (t b) #
Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results, with access the index.
When you don't need access to the index mapM is more liberal in what it can accept.
mapM≡imapM.const
iforM :: (TraversableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m (t b) #
imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b) #
Generalizes mapAccumR to add access to the index.
imapAccumR accumulates state from right to left.
mapAccumR≡imapAccumR.const
imapAccumL :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b) #
Generalizes mapAccumL to add access to the index.
imapAccumL accumulates state from left to right.
mapAccumL≡imapAccumL.const
Indexed Folds with Reified Monoid
ifoldMapBy :: FoldableWithIndex i t => (r -> r -> r) -> r -> (i -> a -> r) -> t a -> r #
ifoldMapByOf :: IndexedFold i t a -> (r -> r -> r) -> r -> (i -> a -> r) -> t -> r #
Indexed Traversals with Reified Applicative
itraverseBy :: TraversableWithIndex i t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (i -> a -> f b) -> t a -> f (t b) #
itraverseByOf :: IndexedTraversal i s t a b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (i -> a -> f b) -> s -> f t #