Open
Description
Let's say you want to pipe some value a
through 3 functions f1
, f2
, f3
, in that order. How would you do it?
Well, you can do it the "normal" way (pure JS):
f3(f2(f1(a)))
Or you can use _.compose()
:
_.compose( f3
, f2
, f1
)(a)
But what I'd really like to write is:
_.pipe( a
, f1
, f2
, f3
)
Both JS's function composition syntax and _.compose()
make me write the function list in the reverse order. Clojure has threading macros; in Elm, you could write this using the reverse apply operator:
a
|> f1
|> f2
|> f3
This _.pipe()
function I'm suggesting would be a way of doing something similar in JS.