3 ms·
|> is (not, see below) mere function composition function compose(f, g) { return function inner(x) { return f(g(x)); } } this is n
by tel 12y ago
|> is (not, see below) mere function composition
function compose(f, g) {
return function inner(x) {
return f(g(x));
}
}
this is not the right kind of composition for something like nested callbacks. For that you need slightly more.
Edit:
It's actually the "apply" operator which looks like
function apply(f) {
return function applied(x) {
return f(x);
}
}
Apply and compose work together nicely. For instance, in Haskell apply is ($) and compose is (.), so you can build a compositional pipeline and apply it like
f . g . h $ x
or like
f $ g $ h $ x
since association goes this way
f $ (g $ (h $ x))
- deleted 12y ago[deleted]
- tel 12y agoAh, my bad, I was distracted writing. It's Haskell's ($), not the (.).
- rubiquity 12y agoNo worries. I deleted my post before your reply came through because I didn't feel my example was good and I'm struggling to do better this early in the morning :D In a lot of cases compose and |> will be similar due to operations that are commutative, but they are semantically different.