4 ms·
I feel like that just confuses things for no good reason. It's no fewer characters than parens but provides as I see it less clarity.
by donatj 11y ago
I feel like that just confuses things for no good reason. It's no fewer characters than parens but provides as I see it less clarity.
- efdee 11y agoI think the clarity comes from the reading order. str |> method1 |> method2 |> method3 vs method3(method2(method1(str))).
- mbreese 11y agoThat's readable in the simple case, (arg1 is a string, returns a string). What about the more complex cases? Different method signatures, required extra arguments, returning objects or arrays? This will either a) break in those cases, or b) not be applicable. In which case, it's extra complexity for very little gain. Seriously, this just seems like syntax sugar that just isn't needed. I get that you might not think it's elegant, but is anyone seriously troubled or confused by method3(method2(method1(str)))? How would the pipeline syntax help here?
- whichdan 11y agoYep; same reason Lodash implements _.flow and _.compose. It also encourages you to write methods that take a single argument and return a single value, or partially apply those that don't.
- coldtea 11y agoHow it's "less clarity"? What happens is much easier to read if you know what the operator means. The only way the old way has more clarity is in the "we are already familiar with it" way. In any other way, this method trumps it.
- bratsche 11y agoIt's much less clear than the F# and Elixir versions of |> are, so if you've used those languages this feels confusing looking. It would be nice to introduce |> into Javascript while keeping it just as understandable as it is in every other language that already has it.