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

How does the reduce call work in the reverse() example? #109

Closed
tsummerall opened this issue Jul 23, 2015 · 10 comments
Closed

How does the reduce call work in the reverse() example? #109

tsummerall opened this issue Jul 23, 2015 · 10 comments

Comments

@tsummerall
Copy link

I can't find an implementation of reduce() that this line of code works with from your example:

var reverse = reduce(function(acc, x){ return [x].concat(acc); }, []);

Is it a typo or can you provide a link that would explain how this reverse function operates?

And, to demonstrate my further confusion, shouldn't reverse be in the form of a composable pure function with one argument, as in reverse=function(x) {..} in order to be used with compose?

@Bondifrench
Copy link

If you are talking from Chapter 5, reduce is actually _.reduce() from the Ramda library, which has been curried.

DrBoolean needs to prefix a few functions explicitly with _., so it's obvious they are coming from a library.

@tsummerall
Copy link
Author

Thanks!

This construction is esoteric enough to non-Ramda users that a sidebar about how it operates would be worthwhile I think. As far as I can tell, the commonly-used underscore.js implementation of reduce() wouldn't allow this trick.

In particular I'm not understanding how reduce digests the empty array it's given in the example.

@DrBoolean
Copy link

I have a video available that talks about reduce: https://www.youtube.com/watch?v=JZSoPZUoR58

@tsummerall
Copy link
Author

That's a great video, thanks!

@jirutka
Copy link
Contributor

jirutka commented Jul 24, 2015

@DrBoolean Heh, funny thing: I know you from your talk “Hey Underscore, You're Doing It Wrong!,” but didn’t know that you are Dr. Boolean, until know!

@DrBoolean
Copy link

ha, yeah. My avatar is a disguise!

@kdamball
Copy link
Contributor

@DrBoolean YOU'RE THAT DUDE FROM THE UNDERSCORE VIDEO?

@DrBoolean
Copy link

haha, yep!

@kdamball
Copy link
Contributor

I know of a few parties later this evening, if you still need one!

@DrBoolean
Copy link

ha. Leave it to me to forever ask the world where the party's at.

@KtorZ KtorZ closed this as completed in ab1353b Feb 20, 2016
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

5 participants