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
editIn Elixir:
"The quick brown fox" |> String.upcase() |> String.split() # Result: ["THE", "QUICK", "BROWN", "FOX"]
Why
editThe written sequence of functions corresponds to how are applied one after another, which makes the code more natural to read.
Why not
editThere 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
editSources
edit- David Thomas; Andrew Hunt (2019). The Pragmatic Programmer (20th Anniversary ed.). Addison-Wesley Professional. ISBN 978-0135957059.