-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add input list transformation functions #3
base: main
Are you sure you want to change the base?
Conversation
Sorry for the delay. I'm busy preparing the |
… request This reverts commit 4c068ae.
Any reason why the functions all have -ed suffixes? It looks like it would be more idiomatic to just call them 'map', 'filter', etc. as foldl was designed to be imported qualified. Anyways, I came here to make a similar pull request, and, because @Gabriel439 has been thinking hard about this, I'm sure I'm overlooking something =) |
I added the -ed suffixes because without them, it sounds like I am working on the output of the fold, not the input. The other (possibly better) options would be using Also, I'm glad to see that this is being revived. |
Hm, it looks like |
Yeah, http://hackage.haskell.org/package/foldl-1.0.6/docs/Control-Foldl.html#v:pretraverse This function supersedes some of the proposed features here, but not all of them, since it lets you apply a traversal upstream of the fold to pick which targets you want to process. For example, you can now implement the proposed http://hackage.haskell.org/package/lens-4.4.0.1/docs/Control-Lens-Fold.html#v:filtered I'm still leaving this ticket open because there are several features proposed which have not been implemented yet. I'm not adding them just yet because I'm trying to see if I can find fold them into a more general pattern. |
This change adds combinators to change the list that is being folded over. For example, a Fold that multiplies the sum of the even numbers and the sum of the odd numbers in a list could be written like this:
Showing it off:
Without these functions, there was no way to easily do this in one traversal.