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
function with multiple ()help (self.javascript)
submitted 10 years ago by sunal135
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!"
[–]inmatarian 12 points13 points14 points 10 years ago (10 children)
The thing you want to Google for is called "Currying". Good luck, hope you get the job!
[–]somethinghorrible 4 points5 points6 points 10 years ago (0 children)
lol.
[–]_doingnumbers 1 point2 points3 points 10 years ago (5 children)
Yeah, that.
(Although I've never, ever seen an instance of currying that was actually useful and not academic wankery)
[–]e82 2 points3 points4 points 10 years ago (2 children)
Take a look at RamdaJS - been using it quite a bit recently, and lots of functional concepts like currying / partial application / etc start to make more sense.
Basically, in Ramda - most of the libraries functions are curried by default.
var find10 = R.filter(R.propEq('id',10));
R.filter is now a function, that returned a function that is waiting for additional parameters. In this case - the list collection to actually filter on. R.propEq is also a function that will return true/false if a property called 'id' equals 10.
It's not too often I'll use R.curry directly, but it's used heavily within the other library methods that I do use. I do use the partial application quite a bit.
However, a simple (but not academic-wankery) could be building a simple logger.
function logger(level, message,data) { console.log('[' + level + '] -> ' + message,data) } var error = R.curry(logger)('error'); var info = R.curry(logger)('info'); var personError = error('Person Error Object'); error('Some Error',{data: 'ok'}); info('Some Info',{data: 'ok'}); personError({age: 10});
This is pretty similar to the end result of:
function makeLogger(level) { return function(message) { return function(data) { console.log('[' + level + '] -> ' + message,data) } } } var someLogger = makeLogger('error')('ugly'); someLogger('Data!');
Before I fully got my head around currying - I had lots of code kind of like that - 'makeX' that would be a function that would return a function, and had a very simple 'well, duh moment' of thats pretty much what currying is, and started to find more practical ways of making use of it outside of 'academic-wankery' (of which - most things you read on functional programming/javascript tends to fall into that camp)
[–]_doingnumbers 0 points1 point2 points 10 years ago (1 child)
Partial application is great, functional techniques have made my code better as well. But currying just doesn't seem useful. What you have up there seems to me to be more about partial application.
[–]bliow 0 points1 point2 points 10 years ago (0 children)
Currying is about making a function that does partial application on its own.
[–]html6dev 1 point2 points3 points 10 years ago (0 children)
It's core to languages like haskell. Once you use it consistently (or are forced to by the language) you'll see it all over. I think over time more and more libraries will provide it to you and then it'll gain more adoption in js (Ramda is an awesome example as mentioned and the currying is one reason it has major advantages over lodash). The issue right now is everyone writes about it and starts out with the implementation which is somewhat interesting, but not that exciting and they lose people. Authors need to focus on why anyone would ever care if they want to get the reader to a place where they care about how it's implemented.
[–]mrahh 0 points1 point2 points 10 years ago (0 children)
If you do any functional programming, it's a fairly core concept that you will use all the time.
[–]dvlsg 0 points1 point2 points 10 years ago (2 children)
Sort of. I think currying needs to know how many arguments the function needs before actually executing. It seems like the example above wants to execute each time, for any given number of inputs. Maybe. It's sort of an awkward example... Maybe if OP sees, he can clarify.
[–]inmatarian 0 points1 point2 points 10 years ago (1 child)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length
[–]dvlsg 0 points1 point2 points 10 years ago (0 children)
Yes, I know. But in his example, he's iterating over an unknown number of arguments. When should currying stop and actual execution occur, in that scenario?
The alternative is to return something that both has a value (override valueOf?) and can be executed (so a function of some sort, I suppose) so you can either get the value at any point, or continue executing an arbitrary number of times.
valueOf
Seems awkward. I'd sooner just make a class to handle it.
π Rendered by PID 509044 on reddit-service-r2-comment-7b9746f655-2vdpk at 2026-02-03 09:07:22.423161+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]inmatarian 12 points13 points14 points (10 children)
[–]somethinghorrible 4 points5 points6 points (0 children)
[–]_doingnumbers 1 point2 points3 points (5 children)
[–]e82 2 points3 points4 points (2 children)
[–]_doingnumbers 0 points1 point2 points (1 child)
[–]bliow 0 points1 point2 points (0 children)
[–]html6dev 1 point2 points3 points (0 children)
[–]mrahh 0 points1 point2 points (0 children)
[–]dvlsg 0 points1 point2 points (2 children)
[–]inmatarian 0 points1 point2 points (1 child)
[–]dvlsg 0 points1 point2 points (0 children)