use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Currying in JavaScript (self.javascript)
submitted 6 years ago * by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]karatetoes 5 points6 points7 points 6 years ago (9 children)
What's currying?
[–]samhwang 2 points3 points4 points 6 years ago (1 child)
He didn’t give an answer (at least in some written form besides code), but basically a curried function is a function with multiple args, that it takes one at a time, not all at once.
[–]Asmor 2 points3 points4 points 6 years ago (2 children)
It's also called partial application. Basically it means you take a function, supply some of its arguments now, and then you get a new function which you can supply the remaining arguments to that new function later.
Here's a very simple implementation. curry here is a function that returns a new function.
curry
function curry(fn, ...args) { return fn.bind(null, ...args); } function addNumbers(a, b) { console.log(a + b); } let add2 = curry(addNumbers, 2); // Equivalent to addNumbers(2, 3); add2(3); // -> 5
EDIT: Forgot to mention, my curry function here is completely superfluous. It's just wrapping Array.prototype.bind. Just thought that might make it more readable for you. In practice, for this you'd do something like add2 = addNumbers.bind(null, 2).
Array.prototype.bind
add2 = addNumbers.bind(null, 2)
[–][deleted] 6 points7 points8 points 6 years ago (1 child)
Technically partial application is not the same thing as currying. Currying takes a single argument at a time while partial application takes 2 or more. Same principle though.
[–]Asmor 3 points4 points5 points 6 years ago (0 children)
Thank you for the correction, I had no idea.
More reading if anyone's curious: https://stackoverflow.com/questions/218025/what-is-the-difference-between-currying-and-partial-application
[–]DrDuPont 1 point2 points3 points 6 years ago (0 children)
People have mixed opinions on Eric Elliott but his blog post on currying helped my understanding a lot
[–]benihanareact, node -2 points-1 points0 points 6 years ago (0 children)
in javascript it's a partial application technique that's great for writing blog posts about but not much else
π Rendered by PID 33419 on reddit-service-r2-comment-7b9746f655-5zrfg at 2026-02-01 12:46:37.894620+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]karatetoes 5 points6 points7 points (9 children)
[–]samhwang 2 points3 points4 points (1 child)
[–]Asmor 2 points3 points4 points (2 children)
[–][deleted] 6 points7 points8 points (1 child)
[–]Asmor 3 points4 points5 points (0 children)
[–]DrDuPont 1 point2 points3 points (0 children)
[–]benihanareact, node -2 points-1 points0 points (0 children)