Data.Traversable.WithIndex

indexed-traversable-0.1.2: FunctorWithIndex, FoldableWithIndex, TraversableWithIndex

Safe Haskell | Safe
Language | Haskell2010

Data.Traversable.WithIndex

Contents

- Indexed Traversables
- Indexed Traversable Combinators
- Default implementations

Description

Indexed Traversables

Synopsis

- class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | 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 | 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)

Minimal complete definition

Nothing

Methods

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

Traverse an indexed container.

    itraverse ≡ itraverseOf itraversed

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

#### Instances

Instances details

TraversableWithIndex () Identity # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (() -> a -> f b) -> Identity a -> f (Identity b) #
TraversableWithIndex () Par1 # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (() -> a -> f b) -> Par1 a -> f (Par1 b) #
TraversableWithIndex () Maybe # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (() -> a -> f b) -> Maybe a -> f (Maybe b) #
TraversableWithIndex Int ZipList # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Int -> a -> f b) -> ZipList a -> f (ZipList b) #
TraversableWithIndex Int IntMap # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Int -> a -> f b) -> IntMap a -> f (IntMap b) #
TraversableWithIndex Int Seq # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Int -> a -> f b) -> Seq a -> f (Seq b) #
TraversableWithIndex Int NonEmpty # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Int -> a -> f b) -> NonEmpty a -> f (NonEmpty b) #
TraversableWithIndex Int [] # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Int -> a -> f b) -> [a] -> f [b] #
TraversableWithIndex Void (Proxy :: Type -> Type) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Void -> a -> f b) -> Proxy a -> f (Proxy b) #
TraversableWithIndex Void (U1 :: Type -> Type) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Void -> a -> f b) -> U1 a -> f (U1 b) #
TraversableWithIndex Void (V1 :: Type -> Type) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Void -> a -> f b) -> V1 a -> f (V1 b) #
Ix i => TraversableWithIndex i (Array i) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (i -> a -> f b) -> Array i a -> f (Array i b) #
TraversableWithIndex k (Map k) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (k -> a -> f b) -> Map k a -> f (Map k b) #
TraversableWithIndex k ((,) k) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (k -> a -> f b) -> (k, a) -> f (k, b) #
TraversableWithIndex Void (Const e :: Type -> Type) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Void -> a -> f b) -> Const e a -> f (Const e b) #
TraversableWithIndex Void (Constant e :: Type -> Type) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Void -> a -> f b) -> Constant e a -> f (Constant e b) #
TraversableWithIndex i f => TraversableWithIndex i (Rec1 f) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => (i -> a -> f0 b) -> Rec1 f a -> f0 (Rec1 f b) #
TraversableWithIndex i f => TraversableWithIndex i (Backwards f) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => (i -> a -> f0 b) -> Backwards f a -> f0 (Backwards f b) #
TraversableWithIndex i m => TraversableWithIndex i (IdentityT m) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (i -> a -> f b) -> IdentityT m a -> f (IdentityT m b) #
TraversableWithIndex i f => TraversableWithIndex i (Reverse f) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => (i -> a -> f0 b) -> Reverse f a -> f0 (Reverse f b) #
TraversableWithIndex Void (K1 i c :: Type -> Type) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => (Void -> a -> f b) -> K1 i c a -> f (K1 i c b) #
TraversableWithIndex [Int] Tree # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f => ([Int] -> a -> f b) -> Tree a -> f (Tree b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Product f g) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> Product f g a -> f0 (Product f g b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Sum f g) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> Sum f g a -> f0 (Sum f g b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :*: g) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> (f :*: g) a -> f0 ((f :*: g) b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :+: g) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> (f :+: g) a -> f0 ((f :+: g) b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (i, j) (Compose f g) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => ((i, j) -> a -> f0 b) -> Compose f g a -> f0 (Compose f g b) #
(TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (i, j) (f :.: g) # |
Instance details Defined in WithIndex Methods itraverse :: Applicative f0 => ((i, j) -> a -> f0 b) -> (f :.: g) a -> f0 ((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.

`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

# Default implementations

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

ifoldMapDefault :: (TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m #