3 ms·
Only complaint here is on the function signature. Normally a pipe operator takes in arguments first and then sequential functions. This pipe function fixes the
by teaearlgraycold 4y ago
Only complaint here is on the function signature. Normally a pipe operator takes in arguments first and then sequential functions. This pipe function fixes the reverse ordering of nested function calls, but the starting inputs will always appear at the end.
You've gone from:
fourth(third(second(first)))
to
pipe(second, third, fourth)(first)
when you could have done
pipe(first, second, third, fourth)
- sfvisser 4y agoYes, more akin to what you’d normally call ‘compose’. Fun stuff nonetheless!
- ledauphin 4y agothis pattern is standard in my experience for function composition. You're creating a function first, which can later be used to derive a result from an input.
- harg 4y agoI agree. This is what fp-ts's pipe[1] function does. It also has flow[2], which is basically a reversed compose. [1]: https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe [2]: https://gcanti.github.io/fp-ts/modules/function.ts.html#flow https://gcanti.github.io/fp-ts/modules/function.ts.html#flow