Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Data.Foldable.WithIndex
Description
Indexed Foldables.
Synopsis
- class Foldable f => FoldableWithIndex i f | f -> i where
- iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- inone :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- none :: Foldable f => (a -> Bool) -> f a -> Bool
- itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f ()
- ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f ()
- imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m ()
- iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m ()
- iconcatMap :: FoldableWithIndex i f => (i -> a -> [b]) -> f a -> [b]
- ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a)
- ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b
- ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b
- itoList :: FoldableWithIndex i f => f a -> [(i, a)]
Indexed Foldables
class Foldable f => FoldableWithIndex i f | f -> i where #
A container that supports folding with an additional index.
Minimal complete definition
Nothing
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
default ifoldMap :: (TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m #
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
Instances
FoldableWithIndex () Identity # | |
Defined in WithIndex | |
FoldableWithIndex () Par1 # | |
FoldableWithIndex () Maybe # | |
FoldableWithIndex Int ZipList # | |
Defined in WithIndex | |
FoldableWithIndex Int NonEmpty # | |
Defined in WithIndex | |
FoldableWithIndex Int IntMap # | |
Defined in WithIndex | |
FoldableWithIndex Int Seq # | |
FoldableWithIndex Int List # | |
FoldableWithIndex Void (Proxy :: Type -> Type) # | |
Defined in WithIndex | |
FoldableWithIndex Void (U1 :: Type -> Type) # | |
FoldableWithIndex Void (V1 :: Type -> Type) # | |
Ix i => FoldableWithIndex i (Array i) # | |
Defined in WithIndex | |
FoldableWithIndex k (Map k) # | |
FoldableWithIndex k ((,) k) # | |
FoldableWithIndex Void (Const e :: Type -> Type) # | |
Defined in WithIndex | |
FoldableWithIndex Void (Constant e :: Type -> Type) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Void -> a -> m) -> Constant e a -> m # ifoldMap' :: Monoid m => (Void -> a -> m) -> Constant e a -> m # ifoldr :: (Void -> a -> b -> b) -> b -> Constant e a -> b # ifoldl :: (Void -> b -> a -> b) -> b -> Constant e a -> b # ifoldr' :: (Void -> a -> b -> b) -> b -> Constant e a -> b # ifoldl' :: (Void -> b -> a -> b) -> b -> Constant e a -> b # | |
FoldableWithIndex i f => FoldableWithIndex i (Rec1 f) # | |
FoldableWithIndex i f => FoldableWithIndex i (Backwards f) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (i -> a -> m) -> Backwards f a -> m # ifoldMap' :: Monoid m => (i -> a -> m) -> Backwards f a -> m # ifoldr :: (i -> a -> b -> b) -> b -> Backwards f a -> b # ifoldl :: (i -> b -> a -> b) -> b -> Backwards f a -> b # | |
FoldableWithIndex i m => FoldableWithIndex i (IdentityT m) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m0 => (i -> a -> m0) -> IdentityT m a -> m0 # ifoldMap' :: Monoid m0 => (i -> a -> m0) -> IdentityT m a -> m0 # ifoldr :: (i -> a -> b -> b) -> b -> IdentityT m a -> b # ifoldl :: (i -> b -> a -> b) -> b -> IdentityT m a -> b # | |
FoldableWithIndex i f => FoldableWithIndex i (Reverse f) # | |
Defined in WithIndex | |
FoldableWithIndex Void (K1 i c :: Type -> Type) # | |
Defined in WithIndex | |
FoldableWithIndex [Int] Tree # | |
Defined in WithIndex | |
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Product f g) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Product f g a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> Product f g a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b # | |
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Sum f g) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Sum f g a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> Sum f g a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b # | |
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :*: g) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b # | |
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :+: g) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b # | |
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (i, j) (Compose f g) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => ((i, j) -> a -> m) -> Compose f g a -> m # ifoldMap' :: Monoid m => ((i, j) -> a -> m) -> Compose f g a -> m # ifoldr :: ((i, j) -> a -> b -> b) -> b -> Compose f g a -> b # ifoldl :: ((i, j) -> b -> a -> b) -> b -> Compose f g a -> b # ifoldr' :: ((i, j) -> a -> b -> b) -> b -> Compose f g a -> b # ifoldl' :: ((i, j) -> b -> a -> b) -> b -> Compose f g a -> b # | |
(FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (i, j) (f :.: g) # | |
Defined in WithIndex Methods ifoldMap :: Monoid m => ((i, j) -> a -> m) -> (f :.: g) a -> m # ifoldMap' :: Monoid m => ((i, j) -> a -> m) -> (f :.: g) a -> m # ifoldr :: ((i, j) -> a -> b -> b) -> b -> (f :.: g) a -> b # ifoldl :: ((i, j) -> b -> a -> b) -> b -> (f :.: g) a -> b # ifoldr' :: ((i, j) -> a -> b -> b) -> b -> (f :.: g) a -> b # ifoldl' :: ((i, j) -> b -> a -> b) -> b -> (f :.: g) a -> b # |
Indexed Foldable Combinators
iany :: 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
iall :: 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
inone :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool #
none :: Foldable f => (a -> Bool) -> f a -> Bool #
Determines whether no elements of the structure satisfy the predicate.
none
f ≡not
.
any
f
itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> 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
ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> 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
imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m () #
Run monadic actions for each target of an IndexedFold
or 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
iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m () #
Run monadic actions for each target of an IndexedFold
or 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
iconcatMap :: 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
ifind :: 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
ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> 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
ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> 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
itoList :: FoldableWithIndex i f => f a -> [(i, a)] #