4 ms·
Decisions, decisions. On one hand, having a pipe is real nice. Some flows are better represented like thwt. On the other, this example doesn't make sense to me
by beebeepka 5y ago
Decisions, decisions.
On one hand, having a pipe is real nice. Some flows are better represented like thwt. On the other, this example doesn't make sense to me.
const y = h(g(f(x)));
const y = x |> f(%) |> g(%) |> h(%)
How is the hack pipe easier on the eyes and mind? Also went through the rest of the article and I have to say things don't get better in terms of readability.
That said, it's arbitrary. I have no doubt many would disagree with me given how often I see people writing code as if it's unthinkable to have more than a handful of symbols on a row.
- ReleaseCandidat 5y agoconst y = h(g(f(x))) const y = x |> f(%) |> g(%) |> h(%) It get's better with const y = g * k + j / w * d - 453368423 |> (x) => { 4566 * x + 46832 - x * x + 1 / x}(%) |> (x) => { x / 4653 + 843 * x *x }(%) |> (x) => { 486543 - x + x * x }(%) The question is if you often do things like that, though ;)
- nmcfarl 5y agoThe example that resonates with me is when the functions have multiple parameters: const y = h(1, g(f("world", x, 3 ),true)) const y = x |> f("world", x, 3) |> g(%, true) |> h(1, %)
- jlokier 5y agoMore readable, imho: const a = g * k + j / w * d - 453368423 const b = 4566 * a + 46832 - a * a + 1 / a const c = b / 4653 + 843 * b * b const y = 486543 - c + c * c
- ReleaseCandidat 5y agoI actually do prefer this too. And when using it for arrays, I'd prefer const r = [a, b, c] .map((e) => 2 * e*e) .filter((e) => e >= 0) .reduce((acc, e) => acc + e) to the new piped version.