sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.04k stars 94 forks source link

fantasy-land: add S.reduce_ #682

Closed davidchambers closed 4 years ago

davidchambers commented 4 years ago

I've wanted this function many times during the past few years. @sanctuary-js/owners, are you in favour of this addition?

Avaq commented 4 years ago

Deleted my previous comment, as I had misunderstood the change.

gabejohnson commented 4 years ago

My only concern is that this function would share the signature of a right fold, but not the behavior. There's nothing wrong about that (functions with different behaviors frequently share the same type signature), just something to consider.

davidchambers commented 4 years ago

My only concern is that this function would share the signature of a right fold, but not the behavior.

Interesting observation, Gabe. I admit that I am not completely comfortable with foldl and foldr in Haskell. It is not clear to me why these functions are of different types:

> :type foldl
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b

> :type foldr
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b

> foldl (\s c -> c:s) "." "abc"
"cba."

> foldr (\c s -> c:s) "." "abc"
"abc."

Thank you for considering this addition, folks. I may be the only person excited about this function, but as no one has voiced opposition, I will merge this pull request. :)