Comment

Comment by notpushkin

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):

    a = b |> c(7) |> d
    a = d(c(7, b))
Too bad it was withdrawn.

[1]: https://github.com/tc39/proposal-smart-pipelines

P. S. When studying Haskell on a CS course in school, I used to define exactly the same squiggly arrow operator for my programs :-)

    x ~> f = f x
parent notpushkin 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton