Software Design/Transform data with pipeline operator

Pipeline operator sends the expression from the left-hand side to the function on the right-hard side. It appears in Elixir[1], Elm,[2] F#[3], Haskell (via a third-party library)[4] and R [5].

Examples

edit

In Elixir:

"The quick brown fox" |> String.upcase() |> String.split() # Result: ["THE", "QUICK", "BROWN", "FOX"]

The written sequence of functions corresponds to how are applied one after another, which makes the code more natural to read.

Why not

edit

There are many situations where the pipeline operator is not applicable: for example when the expression should be sent to a function with several parameters as a non-last parameter. Using several different function application forms can be seen as inconsistency: it's against the practice to always use the same way to do a thing.

edit

Sources

edit
  • David Thomas; Andrew Hunt (2019). The Pragmatic Programmer (20th Anniversary ed.). Addison-Wesley Professional. ISBN 978-0135957059. 

References

edit
  1. "Pipeline operator". Elixir School.
  2. "Elm Syntax".
  3. "F# Function composition and pipelining".
  4. "Flow package".
  5. R-bloggers : the new R pipe