3 ms·
Here are the two forms being offered for a pipe operator: const y = h(g(f(x))); // no pipe const y = x |> f(%) |> g(%) |> h(%); // Hack pipe const y = x
by tzs 5y ago
Here are the two forms being offered for a pipe operator:
const y = h(g(f(x))); // no pipe
const y = x |> f(%) |> g(%) |> h(%); // Hack pipe
const y = x |> f |> g |> h; // F# pipe
Why not use concatenation?
const y = x f g h;
- bryanrasmussen 5y agoIn that case why not write h g f x and keep the ordering of functions the same between the different syntactical structures.
- johannes1234321 5y ago> Why not use concatenation? > > const y = x f g h; This can't be broken into multiple lines. const y = x f g h Will have an implicit ; in between. const y = x |> f |> g |> h; Will work as expected, and potentially increase readability.
- zeroimpl 5y agoBecause then a missing comma somewhere becomes a weird bug, as opposed to a syntax error. Languages with implicit string concatenation using no operator have found it to be a common source of bugs, eg python. See https://news.ycombinator.com/item?id=29841560 https://news.ycombinator.com/item?id=29841560
- angus_gh 5y agoDoes your suggestion allow passing an extra argument into any of those functions? Like the value |> someFunction(1, %, 3)