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

Moduleoptics-core-0.4.1.1Haskell2010

Optics.Internal.Indexed.Classes

Internal implementation details of indexed optics.

This module is intended for internal use only, and may change without warning in subsequent releases.

  • 3 classes
  • 20 values
classclass Functor f => FunctorWithIndex i (f :: Type -> Type) | 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.

Instances30FunctorWithIndex, …
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 foldlOf' is more flexible in what it accepts.

    foldl' l ≡ ifoldl' l . const
    
Instances28FoldableWithIndex, …
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
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
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
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
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
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
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
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
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 mapMOf_ is more flexible in what it accepts.

mapM_ ≡ imapM . 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
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, …
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
valueimapAccumL
  1. :: TraversableWithIndex i t
  2. => i -> s -> a -> (s, b)
  3. -> s
  4. -> t a
  5. -> (s, t b)
#

Generalizes Data.Traversable.mapAccumL to add access to the index.

imapAccumL accumulates state from left to right.

Data.Traversable.mapAccumL ≡ imapAccumL . const
valueimapAccumR
  1. :: TraversableWithIndex i t
  2. => i -> s -> a -> (s, b)
  3. -> s
  4. -> t a
  5. -> (s, t b)
#

Generalizes Data.Traversable.mapAccumR to add access to the index.

imapAccumR accumulates state from right to left.

Data.Traversable.mapAccumR ≡ imapAccumR . const
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