Software Design/Transform data with pipeline operator

From Wikiversity
Jump to navigation Jump to search

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 | edit source]

In Elixir:

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

Why[edit | edit source]

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

Why not[edit | edit source]

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.

Related[edit | edit source]

Sources[edit | edit source]

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

References[edit | edit source]

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