3 ms·
Which aspect, the partial or the pipeline? The partial application operator clearly wins over bind, IMO, which is currently the way you'd do that [ addTwo = ad
by geoelectric 9y ago
Which aspect, the partial or the pipeline?
The partial application operator clearly wins over bind, IMO, which is currently the way you'd do that [ addTwo = add.bind(this, 2) ] if only because you don't need to specify the this parameter. It also gives the option to "bind" to other parameters than the leftmost.
The pipeline operator in that example is a little contrived, but coming from any functional background it makes a ton of sense. Depending on what I was piping, I might also format it more like:
x = 5
|> addTwo
|> add(?, 10)
...which would probably resonate with anyone used to promise chains:
x = Promise.resolve(5)
.then(addTwo)
.then(add(?, 10)) // or v => add(v, 10)
It's still contrived, but it is a reasonably familiar flow in JS. It would also clean up async/await syntax a lot assuming they could be used together:
x = await foo(await bar(2, await baz(3)))
...becomes...
x = await baz(3)
|> await bar(2, ?)
|> await foo(?)
...which honestly is a more accurate representation of what's happening.
- mafro 9y agoThanks for the expanded examples. Maybe I'll like it once I see it in the wild solving real problems.