Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapAccumL and variants #304

Open
andrewthad opened this issue Apr 9, 2021 · 0 comments
Open

mapAccumL and variants #304

andrewthad opened this issue Apr 9, 2021 · 0 comments

Comments

@andrewthad
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant