Partial Application and Lambda Parameter Syntax for JavaScript
medium.com
medium.com
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 :-)
const add = (a,b)=>a+b?
can be partialy applied like the following const add3 = add(3) // this is also a function
You can:
const add3 = add.bind(null, 3)Proper curried languages are definitely better suited for partial application though.
const add = (a, b=0) => {return a+b}
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 :)
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.I'm pretty sure Kotlin borrowed this idea from Groovy.
I'd also like to point out the online playground [0] which allows you to use this directly in your browser and see what it compiles to.
I documented how they work in this part[0] of the readme.
[0]: https://github.com/citycide/param.macro#differences-between-...
I like the direction typescript is going, where you can easily see not only the arity but the type of each parameter, without reading the function body. This is more skimmable.
It's like if mountain-climbing caused more mountains to rise up above you. This is great if you love climbing mountains but terrible if you actually want to reach the top.
We keep "improving" our languages but very few of us take the time to measure our real productivity.
What is the business value case for not using Elm-lang?
At some point, if we are "doing it right" the total amount of code in the world (modulus copies) should be contracting.