-
Notifications
You must be signed in to change notification settings - Fork 24
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
Is there scope for a fold function? #55
Comments
I think this is a great idea, that really gets at how similar lists and maybes are. (Maybes are just a list with 0 or 1 elements.) I only found one person defining a function like this: I also looked to see if there are any other List functions that would be good to add to Maybe.Extra, and found one: |
There's loads here where I'm taking something from an array, updating it and putting it back. For example: |
Thoughts on whether it should be fold : (a -> b -> b) -> b -> Maybe a -> b
maybe
|> Maybe.Extra.fold update updateable vs fold : (a -> b -> b) -> Maybe a -> b -> b
updateable
|> Maybe.Extra.fold update maybe ? And for that matter, thoughts on the argument order of the update function? |
It should follow the pattern for List, Array, etc I would have thought. If you put Probably as well calling it Elm doesn't seem to reverse the accumulator and map in Elm like they do in Haskell between a left and right fold. |
One point for the latter is that it can be quite nice to use it to conditionally add elements to lists: [ some
, list
]
|> Maybe.Extra.fold (::) someMaybeValue Seems reasonably nice... although perhaps a bit on the clever side. |
I'm noticing I'm doing a lot of
when manipulating a couple of arrays. I'll get a value from array1 which is a
Maybe value
, and then apply it to array2 if it exists.My code has lots of
given that's a signature for a fold, is it worth adding it? Which would give
The text was updated successfully, but these errors were encountered: