HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleindexed-traversable-0.1.4Haskell2010

Data.Foldable.WithIndex

Indexed Foldables.

  • 1 class
  • 13 values

Indexed Foldables

1 declaration
classclass Foldable f => FoldableWithIndex i (f :: Type -> Type) | 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' :: 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
    
  • 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 Control.Lens.Fold.foldlOf' is more flexible in what it accepts.

    foldl' l ≡ ifoldl' l . const
    
Instances28FoldableWithIndex, …

Indexed Foldable Combinators

valueiany :: 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
valueiall :: 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
valueinone :: 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
valueitraverse_
  1. :: (FoldableWithIndex i t, Applicative f)
  2. => i -> a -> f b
  3. -> t a
  4. -> 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
valueifor_
  1. :: (FoldableWithIndex i t, Applicative f)
  2. => t a
  3. -> i -> a -> f b
  4. -> 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
valueimapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m ()
#

Run monadic actions for each target of an IndexedFold or Control.Lens.IndexedTraversal.IndexedTraversal with access to the index, discarding the results.

When you don't need access to the index then Control.Lens.Fold.mapMOf_ is more flexible in what it accepts.

mapM_ ≡ imapM . const
valueiforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m ()
#

Run monadic actions for each target of an IndexedFold or Control.Lens.IndexedTraversal.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 forM_ is more flexible in what it accepts.

forM_ a ≡ iforM a . const
valueiconcatMap :: 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
valueifind :: 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
valueifoldrM
  1. :: (FoldableWithIndex i f, Monad m)
  2. => i -> a -> b -> m b
  3. -> b
  4. -> f a
  5. -> 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
valueifoldlM
  1. :: (FoldableWithIndex i f, Monad m)
  2. => i -> b -> a -> m b
  3. -> b
  4. -> f a
  5. -> 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
valueitoList :: 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