Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Indexed Traversables
Synopsis
- 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)
- 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)
- imapDefault :: TraversableWithIndex i f => (i -> a -> b) -> f a -> f b
- ifoldMapDefault :: (TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m
Indexed Traversables
class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i (t :: Type -> Type) | t -> i where Source #
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)
Nothing
itraverse :: Applicative f => (i -> a -> f b) -> t a -> f (t b) Source #
Traverse an indexed container.
itraverse
≡itraverseOf
itraversed
Instances
Indexed Traversable Combinators
ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b) Source #
imapM :: (TraversableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m (t b) Source #
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) Source #
imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b) Source #
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) Source #
Generalizes mapAccumL
to add access to the index.
imapAccumL
accumulates state from left to right.
mapAccumL
≡imapAccumL
.
const
Default implementations
imapDefault :: TraversableWithIndex i f => (i -> a -> b) -> f a -> f b Source #
ifoldMapDefault :: (TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m Source #