lens-4.15.3: Lenses, Folds and Traversals

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 | Haskell98

Control.Lens.Indexed

Contents

- Indexing
- Indexed Functors
- Indexed Foldables
  - Indexed Foldable Combinators
- Converting to Folds
- Restricting by Index
- Indexed Traversables
- Indexed Traversable Combinators
- Indexed Folds with Reified Monoid
- Indexed Traversals with Reified Applicative

Description

(The classes in here need to be defined together for `DefaultSignatures` to work.)

Synopsis

- class Conjoined p => Indexable i p where
- 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 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 | f -> i where
- class Foldable f => FoldableWithIndex i f | f -> i where
- 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 | t -> i where
- 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 where #

This class permits overloading of function application for things that also admit a notion of a key or index.

Minimal complete definition

indexed

Methods

indexed :: p a b -> i -> a -> b #

Build a function from an `indexed` function.

Instances

Indexable i (->) # |
Methods indexed :: (a -> b) -> i -> a -> b #
(~) * i j => Indexable i (Indexed j) # |
Methods indexed :: Indexed j 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 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.

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 (->) # |
Methods distrib :: Functor f => (a -> b) -> f a -> f b # conjoined :: (((* -> * -> *) ~ (->)) (->) -> q (a -> b) r) -> q (a -> b) r -> q (a -> b) r #
Conjoined ReifiedGetter # |
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) # |
Methods distrib :: Functor f => Indexed i a b -> Indexed i (f a) (f b) # conjoined :: (((* -> * -> *) ~ Indexed i) (->) -> q (a -> b) r) -> q (Indexed i a b) r -> q (Indexed i a b) r #

newtype Indexed i a b #

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 runIndexed :: i -> a -> b

Instances

(~) * i j => Indexable i (Indexed j) # |
Methods indexed :: Indexed j a b -> i -> a -> b #
Arrow (Indexed i) # |
Methods arr :: (b -> c) -> Indexed i b c # first :: Indexed i b c -> Indexed i (b, d) (c, d) # second :: Indexed i b c -> Indexed i (d, b) (d, c) # (***) :: Indexed i b c -> Indexed i b' c' -> Indexed i (b, b') (c, c') # (&&&) :: Indexed i b c -> Indexed i b c' -> Indexed i b (c, c') #
ArrowChoice (Indexed i) # |
Methods left :: Indexed i b c -> Indexed i (Either b d) (Either c d) # right :: Indexed i b c -> Indexed i (Either d b) (Either d c) # (+++) :: Indexed i b c -> Indexed i b' c' -> Indexed i (Either b b') (Either c c') # (|||) :: Indexed i b d -> Indexed i c d -> Indexed i (Either b c) d #
ArrowApply (Indexed i) # |
Methods app :: Indexed i (Indexed i b c, b) c #
ArrowLoop (Indexed i) # |
Methods loop :: Indexed i (b, d) (c, d) -> Indexed i b c #
Representable (Indexed i) # |
Associated Types type Rep (Indexed i :: * -> * -> *) :: * -> * # Methods tabulate :: (d -> Rep (Indexed i) c) -> Indexed i d c #
Corepresentable (Indexed i) # |
Associated Types type Corep (Indexed i :: * -> * -> *) :: * -> * # Methods cotabulate :: (Corep (Indexed i) d -> c) -> Indexed i d c #
Closed (Indexed i) # |
Methods closed :: Indexed i a b -> Indexed i (x -> a) (x -> b) #
Choice (Indexed i) # |
Methods left' :: Indexed i a b -> Indexed i (Either a c) (Either b c) # right' :: Indexed i a b -> Indexed i (Either c a) (Either c b) #
Strong (Indexed i) # |
Methods first' :: Indexed i a b -> Indexed i (a, c) (b, c) # second' :: Indexed i a b -> Indexed i (c, a) (c, b) #
Costrong (Indexed i) # |
Methods unfirst :: Indexed i (a, d) (b, d) -> Indexed i a b # unsecond :: Indexed i (d, a) (d, b) -> Indexed i a b #
Profunctor (Indexed i) # |
Methods dimap :: (a -> b) -> (c -> d) -> Indexed i b c -> Indexed i a d # lmap :: (a -> b) -> Indexed i b c -> Indexed i a c # rmap :: (b -> c) -> Indexed i a b -> Indexed i a c # (#.) :: Coercible * c b => (b -> c) -> Indexed i a b -> Indexed i a c # (.#) :: Coercible * b a => Indexed i b c -> (a -> b) -> Indexed i a c #
Conjoined (Indexed i) # |
Methods distrib :: Functor f => Indexed i a b -> Indexed i (f a) (f b) # conjoined :: (((* -> * -> *) ~ Indexed i) (->) -> q (a -> b) r) -> q (Indexed i a b) r -> q (Indexed i a b) r #
Bizarre (Indexed Int) Mafic # |
Methods bazaar :: Applicative f => Indexed Int a (f b) -> Mafic a b t -> f t #
Category * (Indexed i) # |
Methods id :: cat a a # (.) :: cat b c -> cat a b -> cat a c #
Sieve (Indexed i) ((->) i) # |
Methods sieve :: Indexed i a b -> a -> i -> b #
Cosieve (Indexed i) ((,) i) # |
Methods cosieve :: Indexed i a b -> (i, a) -> b #
Sellable (Indexed i) (Molten i) # |
Methods sell :: Indexed i a (Molten i a b b) #
Bizarre (Indexed i) (Molten i) # |
Methods bazaar :: Applicative f => Indexed i a (f b) -> Molten i a b t -> f t #
Monad (Indexed i a) # |
Methods (>>=) :: Indexed i a a -> (a -> Indexed i a b) -> Indexed i a b # (>>) :: Indexed i a a -> Indexed i a b -> Indexed i a b # return :: a -> Indexed i a a # fail :: String -> Indexed i a a #
Functor (Indexed i a) # |
Methods fmap :: (a -> b) -> Indexed i a a -> Indexed i a b # (<$) :: a -> Indexed i a b -> Indexed i a a #
MonadFix (Indexed i a) # |
Methods mfix :: (a -> Indexed i a a) -> Indexed i a a #
Applicative (Indexed i a) # |
Methods pure :: a -> Indexed i a a # (<*>) :: Indexed i a (a -> b) -> Indexed i a a -> Indexed i a b # (*>) :: Indexed i a a -> Indexed i a b -> Indexed i a b # (<*) :: Indexed i a a -> Indexed i a b -> Indexed i a a #
Apply (Indexed i a) # |
Methods (<.>) :: Indexed i a (a -> b) -> Indexed i a a -> Indexed i a b # (.>) :: Indexed i a a -> Indexed i a b -> Indexed i a b # (<.) :: Indexed i a a -> Indexed i a b -> Indexed i a a #
Bind (Indexed i a) # |
Methods (>>-) :: Indexed i a a -> (a -> Indexed i a b) -> Indexed i a b # join :: Indexed i a (Indexed i a a) -> Indexed i a a #
type Rep (Indexed i) # |
type Rep (Indexed i) = (->) i
type Corep (Indexed i) # |
type Corep (Indexed i) = (,) i

(<.) :: 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 `.` g` (and `f `.>` g`) gives you the index of `g` 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 :: IndexedGetter a a b

reindexed :: Indexable j p => (i -> j) -> (Indexed i a b -> r) -> p a b -> r #

Remap the index.

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 :: Traversal s t a b -> IndexedTraversal Int s t a b
    indexing :: Prism s t a b     -> IndexedTraversal Int s t a b
    indexing :: Lens s t a b      -> IndexedLens Int  s t a b
    indexing :: Iso s t a b       -> IndexedLens Int s t a b
    indexing :: Fold s a          -> IndexedFold Int s a
    indexing :: Getter s a        -> IndexedGetter Int s a

    indexing :: Indexable Int p => LensLike (Indexing f) s t a b -> Over p 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 :: Traversal s t a b -> IndexedTraversal Int64 s t a b
    indexing64 :: Prism s t a b     -> IndexedTraversal Int64 s t a b
    indexing64 :: Lens s t a b      -> IndexedLens Int64 s t a b
    indexing64 :: Iso s t a b       -> IndexedLens Int64 s t a b
    indexing64 :: Fold s a          -> IndexedFold Int64 s a
    indexing64 :: Getter s a        -> IndexedGetter Int64 s a

    indexing64 :: Indexable Int64 p => LensLike (Indexing64 f) s t a b -> Over p f s t a b

# Indexed Functors

class Functor f => FunctorWithIndex i f | f -> i where #

A `Functor` with an additional index.

Instances must satisfy a modified form of the `Functor` laws:

    imap f . imap g ≡ imap (\i -> f i . g i)
    imap (\_ a -> a) ≡ id

Methods

imap :: (i -> a -> b) -> f a -> f b #

Map with access to the index.

imap :: TraversableWithIndex i f => (i -> a -> b) -> f a -> f b #

Map with access to the index.

imapped :: 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.

Instances

FunctorWithIndex Int [] # | The position in the list is available as the index.
Methods imap :: (Int -> a -> b) -> [a] -> [b] # imapped :: (Indexable Int p, Settable f) => p a (f b) -> [a] -> f [b] #
FunctorWithIndex Int NonEmpty # |
Methods imap :: (Int -> a -> b) -> NonEmpty a -> NonEmpty b # imapped :: (Indexable Int p, Settable f) => p a (f b) -> NonEmpty a -> f (NonEmpty b) #
FunctorWithIndex Int ZipList # | Same instance as for `[]`.
Methods imap :: (Int -> a -> b) -> ZipList a -> ZipList b # imapped :: (Indexable Int p, Settable f) => p a (f b) -> ZipList a -> f (ZipList b) #
FunctorWithIndex Int IntMap # |
Methods imap :: (Int -> a -> b) -> IntMap a -> IntMap b # imapped :: (Indexable Int p, Settable f) => p a (f b) -> IntMap a -> f (IntMap b) #
FunctorWithIndex Int Seq # | The position in the `Seq` is available as the index.
Methods imap :: (Int -> a -> b) -> Seq a -> Seq b # imapped :: (Indexable Int p, Settable f) => p a (f b) -> Seq a -> f (Seq b) #
FunctorWithIndex Int Vector # |
Methods imap :: (Int -> a -> b) -> Vector a -> Vector b # imapped :: (Indexable Int p, Settable f) => p a (f b) -> Vector a -> f (Vector b) #
FunctorWithIndex Int Deque # |
Methods imap :: (Int -> a -> b) -> Deque a -> Deque b # imapped :: (Indexable Int p, Settable f) => p a (f b) -> Deque a -> f (Deque b) #
FunctorWithIndex () Maybe # |
Methods imap :: (() -> a -> b) -> Maybe a -> Maybe b # imapped :: (Indexable () p, Settable f) => p a (f b) -> Maybe a -> f (Maybe b) #
FunctorWithIndex () Par1 # |
Methods imap :: (() -> a -> b) -> Par1 a -> Par1 b # imapped :: (Indexable () p, Settable f) => p a (f b) -> Par1 a -> f (Par1 b) #
FunctorWithIndex () Identity # |
Methods imap :: (() -> a -> b) -> Identity a -> Identity b # imapped :: (Indexable () p, Settable f) => p a (f b) -> Identity a -> f (Identity b) #
FunctorWithIndex Void V1 # |
Methods imap :: (Void -> a -> b) -> V1 a -> V1 b # imapped :: (Indexable Void p, Settable f) => p a (f b) -> V1 a -> f (V1 b) #
FunctorWithIndex Void U1 # |
Methods imap :: (Void -> a -> b) -> U1 a -> U1 b # imapped :: (Indexable Void p, Settable f) => p a (f b) -> U1 a -> f (U1 b) #
FunctorWithIndex i f => FunctorWithIndex i (Rec1 f) # |
Methods imap :: (i -> a -> b) -> Rec1 f a -> Rec1 f b # imapped :: (Indexable i p, Settable f) => p a (f b) -> Rec1 f a -> f (Rec1 f b) #
Ix i => FunctorWithIndex i (Array i) # |
Methods imap :: (i -> a -> b) -> Array i a -> Array i b # imapped :: (Indexable i p, Settable f) => p a (f b) -> Array i a -> f (Array i b) #
FunctorWithIndex i (Level i) # |
Methods imap :: (i -> a -> b) -> Level i a -> Level i b # imapped :: (Indexable i p, Settable f) => p a (f b) -> Level i a -> f (Level i b) #
FunctorWithIndex r ((->) r) # |
Methods imap :: (r -> a -> b) -> (r -> a) -> r -> b # imapped :: (Indexable r p, Settable f) => p a (f b) -> (r -> a) -> f (r -> b) #
FunctorWithIndex k (HashMap k) # |
Methods imap :: (k -> a -> b) -> HashMap k a -> HashMap k b # imapped :: (Indexable k p, Settable f) => p a (f b) -> HashMap k a -> f (HashMap k b) #
FunctorWithIndex k (Map k) # |
Methods imap :: (k -> a -> b) -> Map k a -> Map k b # imapped :: (Indexable k p, Settable f) => p a (f b) -> Map k a -> f (Map k b) #
FunctorWithIndex k ((,) k) # |
Methods imap :: (k -> a -> b) -> (k, a) -> (k, b) # imapped :: (Indexable k p, Settable f) => p a (f b) -> (k, a) -> f (k, b) #
FunctorWithIndex Void (Proxy *) # |
Methods imap :: (Void -> a -> b) -> Proxy * a -> Proxy * b # imapped :: (Indexable Void p, Settable f) => p a (f b) -> Proxy * a -> f (Proxy * b) #
FunctorWithIndex () (Tagged * a) # |
Methods imap :: (() -> a -> b) -> Tagged * a a -> Tagged * a b # imapped :: (Indexable () p, Settable f) => p a (f b) -> Tagged * a a -> f (Tagged * a b) #
FunctorWithIndex i m => FunctorWithIndex i (IdentityT * m) # |
Methods imap :: (i -> a -> b) -> IdentityT * m a -> IdentityT * m b # imapped :: (Indexable i p, Settable f) => p a (f b) -> IdentityT * m a -> f (IdentityT * m b) #
FunctorWithIndex i f => FunctorWithIndex i (Reverse * f) # |
Methods imap :: (i -> a -> b) -> Reverse * f a -> Reverse * f b # imapped :: (Indexable i p, Settable f) => p a (f b) -> Reverse * f a -> f (Reverse * f b) #
FunctorWithIndex i f => FunctorWithIndex i (Backwards * f) # |
Methods imap :: (i -> a -> b) -> Backwards * f a -> Backwards * f b # imapped :: (Indexable i p, Settable f) => p a (f b) -> Backwards * f a -> f (Backwards * f b) #
FunctorWithIndex Void (K1 i c) # |
Methods imap :: (Void -> a -> b) -> K1 i c a -> K1 i c b # imapped :: (Indexable Void p, Settable f) => p a (f b) -> K1 i c a -> f (K1 i c b) #
FunctorWithIndex i (Magma i t b) # |
Methods imap :: (i -> a -> b) -> Magma i t b a -> Magma i t b b # imapped :: (Indexable i p, Settable f) => p a (f b) -> Magma i t b a -> f (Magma i t b b) #
FunctorWithIndex [Int] Tree # |
Methods imap :: ([Int] -> a -> b) -> Tree a -> Tree b # imapped :: (Indexable [Int] p, Settable f) => p a (f b) -> Tree a -> f (Tree b) #
FunctorWithIndex i f => FunctorWithIndex [i] (Cofree f) # |
Methods imap :: ([i] -> a -> b) -> Cofree f a -> Cofree f b # imapped :: (Indexable [i] p, Settable f) => p a (f b) -> Cofree f a -> f (Cofree f b) #
FunctorWithIndex i f => FunctorWithIndex [i] (Free f) # |
Methods imap :: ([i] -> a -> b) -> Free f a -> Free f b # imapped :: (Indexable [i] p, Settable f) => p a (f b) -> Free f a -> f (Free f b) #
(FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) ((:+:) f g) # |
Methods imap :: (Either i j -> a -> b) -> (f :+: g) a -> (f :+: g) b # imapped :: (Indexable (Either i j) p, Settable f) => p a (f b) -> (f :+: g) a -> f ((f :+: g) b) #
(FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) ((:*:) f g) # |
Methods imap :: (Either i j -> a -> b) -> (f :*: g) a -> (f :*: g) b # imapped :: (Indexable (Either i j) p, Settable f) => p a (f b) -> (f :*: g) a -> f ((f :*: g) b) #
(FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (i, j) ((:.:) f g) # |
Methods imap :: ((i, j) -> a -> b) -> (f :.: g) a -> (f :.: g) b # imapped :: (Indexable (i, j) p, Settable f) => p a (f b) -> (f :.: g) a -> f ((f :.: g) b) #
FunctorWithIndex i w => FunctorWithIndex (s, i) (TracedT s w) # |
Methods imap :: ((s, i) -> a -> b) -> TracedT s w a -> TracedT s w b # imapped :: (Indexable (s, i) p, Settable f) => p a (f b) -> TracedT s w a -> f (TracedT s w b) #
(FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Product * f g) # |
Methods imap :: (Either i j -> a -> b) -> Product * f g a -> Product * f g b # imapped :: (Indexable (Either i j) p, Settable f) => p a (f b) -> Product * f g a -> f (Product * f g b) #
(FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Sum * f g) # |
Methods imap :: (Either i j -> a -> b) -> Sum * f g a -> Sum * f g b # imapped :: (Indexable (Either i j) p, Settable f) => p a (f b) -> Sum * f g a -> f (Sum * f g b) #
FunctorWithIndex i m => FunctorWithIndex (e, i) (ReaderT * e m) # |
Methods imap :: ((e, i) -> a -> b) -> ReaderT * e m a -> ReaderT * e m b # imapped :: (Indexable (e, i) p, Settable f) => p a (f b) -> ReaderT * e m a -> f (ReaderT * e m b) #
(FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (i, j) (Compose * * f g) # |
Methods imap :: ((i, j) -> a -> b) -> Compose * * f g a -> Compose * * f g b # imapped :: (Indexable (i, j) p, Settable f) => p a (f b) -> Compose * * f g a -> f (Compose * * f g b) #

# Indexed Foldables

class Foldable f => FoldableWithIndex i f | f -> i where #

A container that supports folding with an additional index.

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

ifoldMap :: (TraversableWithIndex i f, 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

ifolded :: IndexedFold i (f a) a #

The `IndexedFold` of a `FoldableWithIndex` container.

``ifolded` `.` `asIndex`` is a fold over the keys of a `FoldableWithIndex`.

    >>> Data.Map.fromList [(2, "hello"), (1, "world")]^..ifolded.asIndex
    [1,2]

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

ifoldr' :: (i -> a -> b -> b) -> b -> f a -> b #

Strictly fold right over the elements of a structure 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 #

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

Instances

FoldableWithIndex Int [] # |
Methods ifoldMap :: Monoid m => (Int -> a -> m) -> [a] -> m # ifolded :: (Indexable Int p, Contravariant f, Applicative f) => p a (f a) -> [a] -> f [a] # ifoldr :: (Int -> a -> b -> b) -> b -> [a] -> b # ifoldl :: (Int -> b -> a -> b) -> b -> [a] -> b # ifoldr' :: (Int -> a -> b -> b) -> b -> [a] -> b # ifoldl' :: (Int -> b -> a -> b) -> b -> [a] -> b #
FoldableWithIndex Int NonEmpty # |
Methods ifoldMap :: Monoid m => (Int -> a -> m) -> NonEmpty a -> m # ifolded :: (Indexable Int p, Contravariant f, Applicative f) => p a (f a) -> NonEmpty a -> f (NonEmpty a) # ifoldr :: (Int -> a -> b -> b) -> b -> NonEmpty a -> b # ifoldl :: (Int -> b -> a -> b) -> b -> NonEmpty a -> b # ifoldr' :: (Int -> a -> b -> b) -> b -> NonEmpty a -> b # ifoldl' :: (Int -> b -> a -> b) -> b -> NonEmpty a -> b #
FoldableWithIndex Int ZipList # |
Methods ifoldMap :: Monoid m => (Int -> a -> m) -> ZipList a -> m # ifolded :: (Indexable Int p, Contravariant f, Applicative f) => p a (f a) -> ZipList a -> f (ZipList a) # ifoldr :: (Int -> a -> b -> b) -> b -> ZipList a -> b # ifoldl :: (Int -> b -> a -> b) -> b -> ZipList a -> b # ifoldr' :: (Int -> a -> b -> b) -> b -> ZipList a -> b # ifoldl' :: (Int -> b -> a -> b) -> b -> ZipList a -> b #
FoldableWithIndex Int IntMap # |
Methods ifoldMap :: Monoid m => (Int -> a -> m) -> IntMap a -> m # ifolded :: (Indexable Int p, Contravariant f, Applicative f) => p a (f a) -> IntMap a -> f (IntMap a) # ifoldr :: (Int -> a -> b -> b) -> b -> IntMap a -> b # ifoldl :: (Int -> b -> a -> b) -> b -> IntMap a -> b # ifoldr' :: (Int -> a -> b -> b) -> b -> IntMap a -> b # ifoldl' :: (Int -> b -> a -> b) -> b -> IntMap a -> b #
FoldableWithIndex Int Seq # |
Methods ifoldMap :: Monoid m => (Int -> a -> m) -> Seq a -> m # ifolded :: (Indexable Int p, Contravariant f, Applicative f) => p a (f a) -> Seq a -> f (Seq a) # ifoldr :: (Int -> a -> b -> b) -> b -> Seq a -> b # ifoldl :: (Int -> b -> a -> b) -> b -> Seq a -> b # ifoldr' :: (Int -> a -> b -> b) -> b -> Seq a -> b # ifoldl' :: (Int -> b -> a -> b) -> b -> Seq a -> b #
FoldableWithIndex Int Vector # |
Methods ifoldMap :: Monoid m => (Int -> a -> m) -> Vector a -> m # ifolded :: (Indexable Int p, Contravariant f, Applicative f) => p a (f a) -> Vector a -> f (Vector a) # ifoldr :: (Int -> a -> b -> b) -> b -> Vector a -> b # ifoldl :: (Int -> b -> a -> b) -> b -> Vector a -> b # ifoldr' :: (Int -> a -> b -> b) -> b -> Vector a -> b # ifoldl' :: (Int -> b -> a -> b) -> b -> Vector a -> b #
FoldableWithIndex Int Deque # |
Methods ifoldMap :: Monoid m => (Int -> a -> m) -> Deque a -> m # ifolded :: (Indexable Int p, Contravariant f, Applicative f) => p a (f a) -> Deque a -> f (Deque a) # ifoldr :: (Int -> a -> b -> b) -> b -> Deque a -> b # ifoldl :: (Int -> b -> a -> b) -> b -> Deque a -> b # ifoldr' :: (Int -> a -> b -> b) -> b -> Deque a -> b # ifoldl' :: (Int -> b -> a -> b) -> b -> Deque a -> b #
FoldableWithIndex () Maybe # |
Methods ifoldMap :: Monoid m => (() -> a -> m) -> Maybe a -> m # ifolded :: (Indexable () p, Contravariant f, Applicative f) => p a (f a) -> Maybe a -> f (Maybe a) # ifoldr :: (() -> a -> b -> b) -> b -> Maybe a -> b # ifoldl :: (() -> b -> a -> b) -> b -> Maybe a -> b # ifoldr' :: (() -> a -> b -> b) -> b -> Maybe a -> b # ifoldl' :: (() -> b -> a -> b) -> b -> Maybe a -> b #
FoldableWithIndex () Par1 # |
Methods ifoldMap :: Monoid m => (() -> a -> m) -> Par1 a -> m # ifolded :: (Indexable () p, Contravariant f, Applicative f) => p a (f a) -> Par1 a -> f (Par1 a) # ifoldr :: (() -> a -> b -> b) -> b -> Par1 a -> b # ifoldl :: (() -> b -> a -> b) -> b -> Par1 a -> b # ifoldr' :: (() -> a -> b -> b) -> b -> Par1 a -> b # ifoldl' :: (() -> b -> a -> b) -> b -> Par1 a -> b #
FoldableWithIndex () Identity # |
Methods ifoldMap :: Monoid m => (() -> a -> m) -> Identity a -> m # ifolded :: (Indexable () p, Contravariant f, Applicative f) => p a (f a) -> Identity a -> f (Identity a) # ifoldr :: (() -> a -> b -> b) -> b -> Identity a -> b # ifoldl :: (() -> b -> a -> b) -> b -> Identity a -> b # ifoldr' :: (() -> a -> b -> b) -> b -> Identity a -> b # ifoldl' :: (() -> b -> a -> b) -> b -> Identity a -> b #
FoldableWithIndex Void V1 # |
Methods ifoldMap :: Monoid m => (Void -> a -> m) -> V1 a -> m # ifolded :: (Indexable Void p, Contravariant f, Applicative f) => p a (f a) -> V1 a -> f (V1 a) # ifoldr :: (Void -> a -> b -> b) -> b -> V1 a -> b # ifoldl :: (Void -> b -> a -> b) -> b -> V1 a -> b # ifoldr' :: (Void -> a -> b -> b) -> b -> V1 a -> b # ifoldl' :: (Void -> b -> a -> b) -> b -> V1 a -> b #
FoldableWithIndex Void U1 # |
Methods ifoldMap :: Monoid m => (Void -> a -> m) -> U1 a -> m # ifolded :: (Indexable Void p, Contravariant f, Applicative f) => p a (f a) -> U1 a -> f (U1 a) # ifoldr :: (Void -> a -> b -> b) -> b -> U1 a -> b # ifoldl :: (Void -> b -> a -> b) -> b -> U1 a -> b # ifoldr' :: (Void -> a -> b -> b) -> b -> U1 a -> b # ifoldl' :: (Void -> b -> a -> b) -> b -> U1 a -> b #
FoldableWithIndex i f => FoldableWithIndex i (Rec1 f) # |
Methods ifoldMap :: Monoid m => (i -> a -> m) -> Rec1 f a -> m # ifolded :: (Indexable i p, Contravariant f, Applicative f) => p a (f a) -> Rec1 f a -> f (Rec1 f a) # ifoldr :: (i -> a -> b -> b) -> b -> Rec1 f a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Rec1 f a -> b # ifoldr' :: (i -> a -> b -> b) -> b -> Rec1 f a -> b # ifoldl' :: (i -> b -> a -> b) -> b -> Rec1 f a -> b #
Ix i => FoldableWithIndex i (Array i) # |
Methods ifoldMap :: Monoid m => (i -> a -> m) -> Array i a -> m # ifolded :: (Indexable i p, Contravariant f, Applicative f) => p a (f a) -> Array i a -> f (Array i a) # ifoldr :: (i -> a -> b -> b) -> b -> Array i a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Array i a -> b # ifoldr' :: (i -> a -> b -> b) -> b -> Array i a -> b # ifoldl' :: (i -> b -> a -> b) -> b -> Array i a -> b #
FoldableWithIndex i (Level i) # |
Methods ifoldMap :: Monoid m => (i -> a -> m) -> Level i a -> m # ifolded :: (Indexable i p, Contravariant f, Applicative f) => p a (f a) -> Level i a -> f (Level i a) # ifoldr :: (i -> a -> b -> b) -> b -> Level i a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Level i a -> b # ifoldr' :: (i -> a -> b -> b) -> b -> Level i a -> b # ifoldl' :: (i -> b -> a -> b) -> b -> Level i a -> b #
FoldableWithIndex k (HashMap k) # |
Methods ifoldMap :: Monoid m => (k -> a -> m) -> HashMap k a -> m # ifolded :: (Indexable k p, Contravariant f, Applicative f) => p a (f a) -> HashMap k a -> f (HashMap k a) # ifoldr :: (k -> a -> b -> b) -> b -> HashMap k a -> b # ifoldl :: (k -> b -> a -> b) -> b -> HashMap k a -> b # ifoldr' :: (k -> a -> b -> b) -> b -> HashMap k a -> b # ifoldl' :: (k -> b -> a -> b) -> b -> HashMap k a -> b #
FoldableWithIndex k (Map k) # |
Methods ifoldMap :: Monoid m => (k -> a -> m) -> Map k a -> m # ifolded :: (Indexable k p, Contravariant f, Applicative f) => p a (f a) -> Map k a -> f (Map k a) # ifoldr :: (k -> a -> b -> b) -> b -> Map k a -> b # ifoldl :: (k -> b -> a -> b) -> b -> Map k a -> b # ifoldr' :: (k -> a -> b -> b) -> b -> Map k a -> b # ifoldl' :: (k -> b -> a -> b) -> b -> Map k a -> b #
FoldableWithIndex k ((,) k) # |
Methods ifoldMap :: Monoid m => (k -> a -> m) -> (k, a) -> m # ifolded :: (Indexable k p, Contravariant f, Applicative f) => p a (f a) -> (k, a) -> f (k, a) # ifoldr :: (k -> a -> b -> b) -> b -> (k, a) -> b # ifoldl :: (k -> b -> a -> b) -> b -> (k, a) -> b # ifoldr' :: (k -> a -> b -> b) -> b -> (k, a) -> b # ifoldl' :: (k -> b -> a -> b) -> b -> (k, a) -> b #
FoldableWithIndex Void (Proxy *) # |
Methods ifoldMap :: Monoid m => (Void -> a -> m) -> Proxy * a -> m # ifolded :: (Indexable Void p, Contravariant f, Applicative f) => p a (f a) -> Proxy * a -> f (Proxy * a) # ifoldr :: (Void -> a -> b -> b) -> b -> Proxy * a -> b # ifoldl :: (Void -> b -> a -> b) -> b -> Proxy * a -> b # ifoldr' :: (Void -> a -> b -> b) -> b -> Proxy * a -> b # ifoldl' :: (Void -> b -> a -> b) -> b -> Proxy * a -> b #
FoldableWithIndex () (Tagged * a) # |
Methods ifoldMap :: Monoid m => (() -> a -> m) -> Tagged * a a -> m # ifolded :: (Indexable () p, Contravariant f, Applicative f) => p a (f a) -> Tagged * a a -> f (Tagged * a a) # ifoldr :: (() -> a -> b -> b) -> b -> Tagged * a a -> b # ifoldl :: (() -> b -> a -> b) -> b -> Tagged * a a -> b # ifoldr' :: (() -> a -> b -> b) -> b -> Tagged * a a -> b # ifoldl' :: (() -> b -> a -> b) -> b -> Tagged * a a -> b #
FoldableWithIndex i m => FoldableWithIndex i (IdentityT * m) # |
Methods ifoldMap :: Monoid m => (i -> a -> m) -> IdentityT * m a -> m # ifolded :: (Indexable i p, Contravariant f, Applicative f) => p a (f a) -> IdentityT * m a -> f (IdentityT * m a) # ifoldr :: (i -> a -> b -> b) -> b -> IdentityT * m a -> b # ifoldl :: (i -> b -> a -> b) -> b -> IdentityT * m a -> b # 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) # |
Methods ifoldMap :: Monoid m => (i -> a -> m) -> Reverse * f a -> m # ifolded :: (Indexable i p, Contravariant f, Applicative f) => p a (f a) -> Reverse * f a -> f (Reverse * f a) # ifoldr :: (i -> a -> b -> b) -> b -> Reverse * f a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Reverse * f a -> b # ifoldr' :: (i -> a -> b -> b) -> b -> Reverse * f a -> b # ifoldl' :: (i -> b -> a -> b) -> b -> Reverse * f a -> b #
FoldableWithIndex i f => FoldableWithIndex i (Backwards * f) # |
Methods ifoldMap :: Monoid m => (i -> a -> m) -> Backwards * f a -> m # ifolded :: (Indexable i p, Contravariant f, Applicative f) => p a (f a) -> Backwards * f a -> f (Backwards * f a) # ifoldr :: (i -> a -> b -> b) -> b -> Backwards * f a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Backwards * f a -> b # ifoldr' :: (i -> a -> b -> b) -> b -> Backwards * f a -> b # ifoldl' :: (i -> b -> a -> b) -> b -> Backwards * f a -> b #
FoldableWithIndex Void (K1 i c) # |
Methods ifoldMap :: Monoid m => (Void -> a -> m) -> K1 i c a -> m # ifolded :: (Indexable Void p, Contravariant f, Applicative f) => p a (f a) -> K1 i c a -> f (K1 i c a) # ifoldr :: (Void -> a -> b -> b) -> b -> K1 i c a -> b # ifoldl :: (Void -> b -> a -> b) -> b -> K1 i c a -> b # ifoldr' :: (Void -> a -> b -> b) -> b -> K1 i c a -> b # ifoldl' :: (Void -> b -> a -> b) -> b -> K1 i c a -> b #
FoldableWithIndex i (Magma i t b) # |
Methods ifoldMap :: Monoid m => (i -> a -> m) -> Magma i t b a -> m # ifolded :: (Indexable i p, Contravariant f, Applicative f) => p a (f a) -> Magma i t b a -> f (Magma i t b a) # ifoldr :: (i -> a -> b -> b) -> b -> Magma i t b a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Magma i t b a -> b # ifoldr' :: (i -> a -> b -> b) -> b -> Magma i t b a -> b # ifoldl' :: (i -> b -> a -> b) -> b -> Magma i t b a -> b #
FoldableWithIndex [Int] Tree # |
Methods ifoldMap :: Monoid m => ([Int] -> a -> m) -> Tree a -> m # ifolded :: (Indexable [Int] p, Contravariant f, Applicative f) => p a (f a) -> Tree a -> f (Tree a) # ifoldr :: ([Int] -> a -> b -> b) -> b -> Tree a -> b # ifoldl :: ([Int] -> b -> a -> b) -> b -> Tree a -> b # ifoldr' :: ([Int] -> a -> b -> b) -> b -> Tree a -> b # ifoldl' :: ([Int] -> b -> a -> b) -> b -> Tree a -> b #
FoldableWithIndex i f => FoldableWithIndex [i] (Cofree f) # |
Methods ifoldMap :: Monoid m => ([i] -> a -> m) -> Cofree f a -> m # ifolded :: (Indexable [i] p, Contravariant f, Applicative f) => p a (f a) -> Cofree f a -> f (Cofree f a) # ifoldr :: ([i] -> a -> b -> b) -> b -> Cofree f a -> b # ifoldl :: ([i] -> b -> a -> b) -> b -> Cofree f a -> b # ifoldr' :: ([i] -> a -> b -> b) -> b -> Cofree f a -> b # ifoldl' :: ([i] -> b -> a -> b) -> b -> Cofree f a -> b #
FoldableWithIndex i f => FoldableWithIndex [i] (Free f) # |
Methods ifoldMap :: Monoid m => ([i] -> a -> m) -> Free f a -> m # ifolded :: (Indexable [i] p, Contravariant f, Applicative f) => p a (f a) -> Free f a -> f (Free f a) # ifoldr :: ([i] -> a -> b -> b) -> b -> Free f a -> b # ifoldl :: ([i] -> b -> a -> b) -> b -> Free f a -> b # ifoldr' :: ([i] -> a -> b -> b) -> b -> Free f a -> b # ifoldl' :: ([i] -> b -> a -> b) -> b -> Free f a -> b #
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) ((:+:) f g) # |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f, Applicative f) => p a (f a) -> (f :+: g) a -> f ((f :+: g) a) # 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) # |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f, Applicative f) => p a (f a) -> (f :*: g) a -> f ((f :*: g) a) # 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) ((:.:) f g) # |
Methods ifoldMap :: Monoid m => ((i, j) -> a -> m) -> (f :.: g) a -> m # ifolded :: (Indexable (i, j) p, Contravariant f, Applicative f) => p a (f a) -> (f :.: g) a -> f ((f :.: g) a) # 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 #
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Product * f g) # |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Product * f g a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f, Applicative f) => p a (f a) -> Product * f g a -> f (Product * f g a) # 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) # |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Sum * f g a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f, Applicative f) => p a (f a) -> Sum * f g a -> f (Sum * f g a) # 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 (i, j) (Compose * * f g) # |
Methods ifoldMap :: Monoid m => ((i, j) -> a -> m) -> Compose * * f g a -> m # ifolded :: (Indexable (i, j) p, Contravariant f, Applicative f) => p a (f a) -> Compose * * f g a -> f (Compose * * f g a) # 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 #

## Indexed Foldable Combinators

iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool #

Return whether or not any element in a container satisfies a predicate, with access to the index `i`.

When you don't need access to the index then `any` is more flexible in what it accepts.

    any ≡ iany . const

iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool #

Return whether or not all elements in a container satisfy a predicate, with access to the index `i`.

When you don't need access to the index then `all` is more flexible in what it accepts.

    all ≡ iall . const

inone :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool #

Return whether or not none of the elements in a container satisfy a predicate, with access to the index `i`.

When you don't need access to the index then `none` is more flexible in what it accepts.

    none ≡ inone . const
    inone f ≡ not . iany f

none :: Foldable f => (a -> Bool) -> f a -> Bool #

Determines whether no elements of the structure satisfy the predicate.

    none f ≡ not . any f

itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f () #

Traverse elements with access to the index `i`, discarding the results.

When you don't need access to the index then `traverse_` is more flexible in what it accepts.

    traverse_ l = itraverse . const

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_ ≡ flip itraverse_

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 () #

Run monadic actions for each target of an `IndexedFold` or `IndexedTraversal` with access to the index, discarding the results (with the arguments flipped).

    iforM_ ≡ flip imapM_

When you don't need access to the index then `forMOf_` is more flexible in what it accepts.

    forMOf_ l a ≡ iforMOf l a . const

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 . const
    iconcatMap ≡ ifoldMap

ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a) #

Searches a container with a predicate that is also supplied the index, returning 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 `find` is more flexible in what it accepts.

    find ≡ ifind . const

ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b #

Monadic fold right over the elements of a structure with an index.

When you don't need access to the index then `foldrM` is more flexible in what it accepts.

    foldrM ≡ ifoldrM . const

ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b #

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 `foldlM` is more flexible in what it accepts.

    foldlM ≡ ifoldlM . const

itoList :: FoldableWithIndex i f => f a -> [(i, a)] #

Extract the key-value pairs from a structure.

When you don't need access to the indices in the result, then `toList` is more flexible in what it accepts.

    toList ≡ map snd . itoList

# 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 2
    Just "world"

# Indexed Traversables

class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i where #

A `Traversable` with an additional index.

An instance must satisfy a (modified) form of the `Traversable` laws:

    itraverse (const Identity) ≡ Identity
    fmap (itraverse f) . itraverse g ≡ getCompose . itraverse (\i -> Compose . fmap (f i) . g i)

Methods

itraverse :: Applicative f => (i -> a -> f b) -> t a -> f (t b) #

Traverse an indexed container.

    itraverse ≡ itraverseOf itraversed

itraverse :: (i ~ Int, Applicative f) => (i -> a -> f b) -> t a -> f (t b) #

Traverse an indexed container.

    itraverse ≡ itraverseOf itraversed

itraversed :: IndexedTraversal i (t a) (t b) a b #

The `IndexedTraversal` of a `TraversableWithIndex` container.

Instances

TraversableWithIndex Int [] # |
Methods itraverse :: Applicative f => (Int -> a -> f b) -> [a] -> f [b] # itraversed :: (Indexable Int p, Applicative f) => p a (f b) -> [a] -> f [b] #
TraversableWithIndex Int NonEmpty # |
Methods itraverse :: Applicative f => (Int -> a -> f b) -> NonEmpty a -> f (NonEmpty b) # itraversed :: (Indexable Int p, Applicative f) => p a (f b) -> NonEmpty a -> f (NonEmpty b) #
TraversableWithIndex Int ZipList # |
Methods itraverse :: Applicative f => (Int -> a -> f b) -> ZipList a -> f (ZipList b) # itraversed :: (Indexable Int p, Applicative f) => p a (f b) -> ZipList a -> f (ZipList b) #
TraversableWithIndex Int IntMap # |
Methods itraverse :: Applicative f => (Int -> a -> f b) -> IntMap a -> f (IntMap b) # itraversed :: (Indexable Int p, Applicative f) => p a (f b) -> IntMap a -> f (IntMap b) #
TraversableWithIndex Int Seq # |
Methods itraverse :: Applicative f => (Int -> a -> f b) -> Seq a -> f (Seq b) # itraversed :: (Indexable Int p, Applicative f) => p a (f b) -> Seq a -> f (Seq b) #
TraversableWithIndex Int Vector # |
Methods itraverse :: Applicative f => (Int -> a -> f b) -> Vector a -> f (Vector b) # itraversed :: (Indexable Int p, Applicative f) => p a (f b) -> Vector a -> f (Vector b) #
TraversableWithIndex Int Deque # |
Methods itraverse :: Applicative f => (Int -> a -> f b) -> Deque a -> f (Deque b) # itraversed :: (Indexable Int p, Applicative f) => p a (f b) -> Deque a -> f (Deque b) #
TraversableWithIndex () Maybe # |
Methods itraverse :: Applicative f => (() -> a -> f b) -> Maybe a -> f (Maybe b) # itraversed :: (Indexable () p, Applicative f) => p a (f b) -> Maybe a -> f (Maybe b) #
TraversableWithIndex () Par1 # |
Methods itraverse :: Applicative f => (() -> a -> f b) -> Par1 a -> f (Par1 b) # itraversed :: (Indexable () p, Applicative f) => p a (f b) -> Par1 a -> f (Par1 b) #
TraversableWithIndex () Identity # |
Methods itraverse :: Applicative f => (() -> a -> f b) -> Identity a -> f (Identity b) # itraversed :: (Indexable () p, Applicative f) => p a (f b) -> Identity a -> f (Identity b) #
TraversableWithIndex Void V1 # |
Methods itraverse :: Applicative f => (Void -> a -> f b) -> V1 a -> f (V1 b) # itraversed :: (Indexable Void p, Applicative f) => p a (f b) -> V1 a -> f (V1 b) #
TraversableWithIndex Void U1 # |
Methods itraverse :: Applicative f => (Void -> a -> f b) -> U1 a -> f (U1 b) # itraversed :: (Indexable Void p, Applicative f) => p a (f b) -> U1 a -> f (U1 b) #
TraversableWithIndex i f => TraversableWithIndex i (Rec1 f) # |
Methods itraverse :: Applicative f => (i -> a -> f b) -> Rec1 f a -> f (Rec1 f b) # itraversed :: (Indexable i p, Applicative f) => p a (f b) -> Rec1 f a -> f (Rec1 f b) #
Ix i => TraversableWithIndex i (Array i) # |
Methods itraverse :: Applicative f => (i -> a -> f b) -> Array i a -> f (Array i b) # itraversed :: (Indexable i p, Applicative f) => p a (f b) -> Array i a -> f (Array i b) #
TraversableWithIndex i (Level i) # |
Methods itraverse :: Applicative f => (i -> a -> f b) -> Level i a -> f (Level i b) # itraversed :: (Indexable i p, Applicative f) => p a (f b) -> Level i a -> f (Level i b) #
TraversableWithIndex k (HashMap k) # |
Methods itraverse :: Applicative f => (k -> a -> f b) -> HashMap k a -> f (HashMap k b) # itraversed :: (Indexable k p, Applicative f) => p a (f b) -> HashMap k a -> f (HashMap k b) #
TraversableWithIndex k (Map k) # |
Methods itraverse :: Applicative f => (k -> a -> f b) -> Map k a -> f (Map k b) # itraversed :: (Indexable k p, Applicative f) => p a (f b) -> Map k a -> f (Map k b) #
TraversableWithIndex k ((,) k) # |
Methods itraverse :: Applicative f => (k -> a -> f b) -> (k, a) -> f (k, b) # itraversed :: (Indexable k p, Applicative f) => p a (f b) -> (k, a) -> f (k, b) #
TraversableWithIndex Void (Proxy *) # |
Methods itraverse :: Applicative f => (Void -> a -> f b) -> Proxy * a -> f (Proxy * b) # itraversed :: (Indexable Void p, Applicative f) => p a (f b) -> Proxy * a -> f (Proxy * b) #
TraversableWithIndex () (Tagged * a) # |
Methods itraverse :: Applicative f => (() -> a -> f b) -> Tagged * a a -> f (Tagged * a b) # itraversed :: (Indexable () p, Applicative f) => p a (f b) -> Tagged * a a -> f (Tagged * a b) #
TraversableWithIndex i m => TraversableWithIndex i (IdentityT * m) # |
Methods itraverse :: Applicative f => (i -> a -> f b) -> IdentityT * m a -> f (IdentityT * m b) # itraversed :: (Indexable i p, Applicative f) => p a (f b) -> IdentityT * m a -> f (IdentityT * m b) #
TraversableWithIndex i f => TraversableWithIndex i (Reverse * f) # |
Methods itraverse :: Applicative f => (i -> a -> f b) -> Reverse * f a -> f (Reverse * f b) # itraversed :: (Indexable i p, Applicative f) => p a (f b) -> Reverse * f a -> f (Reverse * f b) #
TraversableWithIndex i f => TraversableWithIndex i (Backwards * f) # |
Methods itraverse :: Applicative f => (i -> a -> f b) -> Backwards * f a -> f (Backwards * f b) # itraversed :: (Indexable i p, Applicative f) => p a (f b) -> Backwards * f a -> f (Backwards * f b) #
TraversableWithIndex Void (K1 i c) # |
Methods itraverse :: Applicative f => (Void -> a -> f b) -> K1 i c a -> f (K1 i c b) # itraversed :: (Indexable Void p, Applicative f) => p a (f b) -> K1 i c a -> f (K1 i c b) #
TraversableWithIndex i (Magma i t b) # |
Methods itraverse :: Applicative f => (i -> a -> f b) -> Magma i t b a -> f (Magma i t b b) # itraversed :: (Indexable i p, Applicative f) => p a (f b) -> Magma i t b a -> f (Magma i t b b) #
TraversableWithIndex [Int] Tree # |
Methods itraverse :: Applicative f => ([Int] -> a -> f b) -> Tree a -> f (Tree b) # itraversed :: (Indexable [Int] p, Applicative f) => p a (f b) -> Tree a -> f (Tree b) #
TraversableWithIndex i f => TraversableWithIndex [i] (Cofree f) # |
Methods itraverse :: Applicative f => ([i] -> a -> f b) -> Cofree f a -> f (Cofree f b) # itraversed :: (Indexable [i] p, Applicative f) => p a (f b) -> Cofree f a -> f (Cofree f b) #
TraversableWithIndex i f => TraversableWithIndex [i] (Free f) # |
Methods itraverse :: Applicative f => ([i] -> a -> f b) -> Free f a -> f (Free f b) # itraversed :: (Indexable [i] p, Applicative f) => p a (f b) -> Free f a -> f (Free f b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) ((:+:) f g) # |
Methods itraverse :: Applicative f => (Either i j -> a -> f b) -> (f :+: g) a -> f ((f :+: g) b) # itraversed :: (Indexable (Either i j) p, Applicative f) => p a (f b) -> (f :+: g) a -> f ((f :+: g) b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) ((:*:) f g) # |
Methods itraverse :: Applicative f => (Either i j -> a -> f b) -> (f :*: g) a -> f ((f :*: g) b) # itraversed :: (Indexable (Either i j) p, Applicative f) => p a (f b) -> (f :*: g) a -> f ((f :*: g) b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (i, j) ((:.:) f g) # |
Methods itraverse :: Applicative f => ((i, j) -> a -> f b) -> (f :.: g) a -> f ((f :.: g) b) # itraversed :: (Indexable (i, j) p, Applicative f) => p a (f b) -> (f :.: g) a -> f ((f :.: g) b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Product * f g) # |
Methods itraverse :: Applicative f => (Either i j -> a -> f b) -> Product * f g a -> f (Product * f g b) # itraversed :: (Indexable (Either i j) p, Applicative f) => p a (f b) -> Product * f g a -> f (Product * f g b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Sum * f g) # |
Methods itraverse :: Applicative f => (Either i j -> a -> f b) -> Sum * f g a -> f (Sum * f g b) # itraversed :: (Indexable (Either i j) p, Applicative f) => p a (f b) -> Sum * f g a -> f (Sum * f g b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (i, j) (Compose * * f g) # |
Methods itraverse :: Applicative f => ((i, j) -> a -> f b) -> Compose * * f g a -> f (Compose * * f g b) # itraversed :: (Indexable (i, j) p, Applicative f) => p a (f b) -> Compose * * f g a -> f (Compose * * f g b) #

# Indexed Traversable Combinators

ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b) #

Traverse with an index (and the arguments flipped).

    for a ≡ ifor a . const
    ifor ≡ flip itraverse

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) #

Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results, with access its position (and the arguments flipped).

    forM a ≡ iforM a . const
    iforM ≡ flip imapM

imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b) #

Generalizes `mapAccumR` to add access to the index.

`imapAccumROf` 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.

`imapAccumLOf` accumulates state from left to right.

    mapAccumLOf ≡ 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 #