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

fantasy-land: add S.reduce_ #682

Merged
merged 1 commit into from
Jul 25, 2020
Merged

fantasy-land: add S.reduce_ #682

merged 1 commit into from
Jul 25, 2020

Conversation

davidchambers
Copy link
Member

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

eq (S.show (S.reduce)) ('reduce :: Foldable f => (a -> b -> a) -> a -> f b -> a');
eq (S.show (S.reduce)) ('reduce :: Foldable f => (b -> a -> b) -> b -> f a -> b');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this signature to match the signature used in the documentation.

@Avaq
Copy link
Member

Avaq commented Jul 19, 2020

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

Copy link
Member

@Avaq Avaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this change.

Copy link
Member

@Bradcomp Bradcomp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:bowtie: This seems like a reasonable addition.

@gabejohnson
Copy link
Member

gabejohnson commented Jul 20, 2020

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
Copy link
Member Author

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. :)

@davidchambers davidchambers merged commit 354f571 into master Jul 25, 2020
@davidchambers davidchambers deleted the davidchambers/reduce branch July 25, 2020 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants