haskell / haskell/primitive

mapAccumL and variants

Open
#304 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
123
Forks
60
PR merge metrics
No merged PRs in 30d

Description

In Data.List, there is a function that maps over a collection while building an accumulator:

mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)

Specialized to `Array`, this would be:

mapAccumL :: (a -> b -> (a, c)) -> a -> Array b -> (a, Array c)

This is basically a combination of `foldl` and `map`. There is a less expressive variant of this where the accumulator is a `Monoid` and you do not inspect it (a comparison to the contrast between `Writer` and `State` is apt here). This variant looks like this:

mapAccumMonoid :: Monoid a => (b -> (a, c)) -> Array b -> (a, Array c)

I use this function somewhat often. I've thought about adding it to `primitive`, but I'm going to just add it to contiguous for the time being. Just wanted to get these thoughts written down somewhere.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.