[Syntax]Pipe operator (reverse application) #457
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Close #455. Add a reverse application operator to nicely write a sequence of transformation as something like a Unix pipeline.
Usually you want this operator to not take precedence too much, to avoid parentheses around the initial expression such as
x * 2 |> nums.pow 2
and such that it can also serve as a Haskell's$
, just reversed. I put it at a similar precedence level as in OCaml, where it takes higher precedence than boolean operators like&&
and||
. However Haskell's$
and Elm|>
take the lowest precedence of all operators, even than boolean ones. I'm not sure how much it matters: shouldfoo && bar |> stuff |> otherstuff
be interpreted asfoo && (bar |> stuff |> otherstuff)
or(foo && bar) |> stuff |> otherstuff
? I don't have a strong opinion, although I arbitrarily prefer the first option, as is implemented in this PR.