Re:Partial Application and Lambda Parameter Syntax for JavaS...
by citycide on Wednesday January 31, 2018 @11:47AM
(#16275215)
Right, this is currying not partial application. And it comes with the drawback that you always have to call the function multiple times. You can't provide all the parameters in one list, which rules out things like spread arguments. That's not the case with `param.macro`, depending on how you apply of course.
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by Traubenfuchs on Wednesday January 31, 2018 @03:24AM
(#16272365)
Am I missing something? Why not just
const add = (a,b)=>a+b?
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by a-saleh on Wednesday January 31, 2018 @05:09AM
(#16272794)
Well usually it would be for something that is useful, like
const greaterThan = x => y => y > x
and then I can do thins like
numbers.filter(greaterThan(10))
because greatherThan(10) is a function (and I hope I did put the correct comparison operator :)
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by masklinn on Wednesday January 31, 2018 @05:20AM
(#16272842)
It also works better on languages using free functions than those using method calls e.g. in Haskell you have
filter :: (a -> Bool) -> [a] -> [a]
so you partially apply to a predicate to get a specific filter condition which you can apply to various contexts e.g. over10 = filter (>= 10)
That's why functional languages tend to put the callback first in HoFs, it's usually the more common partial application case.
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by ponkin on Wednesday January 31, 2018 @03:53AM
(#16272481)
You can not use partial application with that.
for example
const add = x=>y=>x+y
can be partialy applied like the following const add3 = add(3) // this is also a function
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by masklinn on Wednesday January 31, 2018 @05:22AM
(#16272853)
> You can not use partial application with that.
You can:
const add3 = add.bind(null, 3)
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by a-saleh on Wednesday January 31, 2018 @11:27AM
(#16275051)
I still like currying better, but I just might be weird like that :-)
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by masklinn on Wednesday January 31, 2018 @11:36AM
(#16275122)
I only asserted that you could partially apply regular functions. But I don't think currying looks or feels nice in Javascript.
Proper curried languages are definitely better suited for partial application though.
Re:Partial Application and Lambda Parameter Syntax for JavaS...
by mwilliaams on Wednesday January 31, 2018 @02:16PM
(#16276654)
You could use default parameters in this case.
const add = (a, b=0) => {return a+b}
const add = x => y => x + y
This is definitely non-idiomatic, but the definition syntax itself doesn't look that bad, if you can stomach writing add(1)(2) to use it.
I do agree that using _ would probably be a better solution :-)