It feels a bit unnatural to pipe multiple arguments like that in JS, and you could inline them in the first call without losing legibility:
a = c(b, 7) |> d(%)
It's the arguments added way down the line that are problematic:
a = f((e(d(c(b))), 4), 5)
a = ((b ~> c ~> d), 4 ~> e), 5 ~> f
a = b |> c(%) |> d(%) |> e(%, 4) |> f(%, 5)
Smart pipes [1] were a bit nicer about that:
a = b |> c |> d |> e(#, 4) |> f(#, 5)
Basically you would use # token whenever you wanted an expression and just a function name when you needed to pass a single argument. Best of both worlds IMO.
Perhaps it could even be extended for Curry-ish function syntax (although it isn't as obvious):
> P. S. When studying Haskell on a CS course in school, I used to define exactly the same squiggly arrow operator for my programs :-)
Haskell base already has the reverse application operator (&) which does the same thing. Not included in the prelude but can be imported from Data.Function. [1] It's defined as:
(&) :: a -> (a -> b) -> b
x & f = f x
Not that there's anything wrong with using your own definitions, just thought I'd point it out!
That has 4 opening parenthesis and 5 closing parenthesis.
b is passed to c
b ~> c
then the result is passed to d
b ~> c ~> d
then to e along with 4 as a second parameter
b ~> c ~> d,4 ~> e
and finally to f along with 5
b ~> c ~> d,4 ~> e,5 ~> f
The nice aspect of "this ~> that" is that the meaning is simply "put this into that". And that it results in the shortest code.
An alternative would be:
b ~> c ~> d ~> e(%,4)
Slightly longer, but maybe easier to read. Also easier to handle, as you can remove the fourth part " ~> e(%,4)" without having to change the third part.