HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduleindexed-traversable-0.1.5Haskell2010

Data.Traversable.WithIndex

Indexed Traversables

  • 1 class
  • 7 values

Indexed Traversables

1 declaration
classclass (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 (const Identity) ≡ Identity
fmap (itraverse f) . itraverse g ≡ getCompose . itraverse (\i -> Compose . fmap (f i) . g i)

Methods

Instances28TraversableWithIndex, …

Indexed Traversable Combinators

5 declarations
valueimapM
  1. :: (TraversableWithIndex i t, Monad m)
  2. => i -> a -> m b
  3. -> t a
  4. -> 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
valueiforM
  1. :: (TraversableWithIndex i t, Monad m)
  2. => t a
  3. -> i -> a -> m b
  4. -> 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

Default implementations

2 declarations