How To Use Elm Pipe Operator — Tentamen Software Testing Blog
In the previous post, we learned how to use the JSON decoder in Elm REPL. Today we move on to practical usage of Elm pipe operator. This post is part of the functional language series, and it is based on a remarkable book, Programming Elm Build Safe and Maintainable Front-End Applications by Jeremy Fairbank.
The Pipe Operator
The Pipe operator is used for function compositions. Function composition is when you create a function using several small functions. The output of a function is piped as the input of another function. If the next pipe function has several input parameters, the output is piped as the last parameter (remember that in Elixir, this is the first parameter).
For example, we will pipe multiply and divide functions, which together create multiplication inverse function. In the above screenshot, we first create
multiply. The second one is
divide that divides the second parameter from the first one.
inverse function pipes
divide. Do you know why divide functions divide second with the first parameter?
- the Elm pipe operator is handy for function composition.
- Pipe operator notation is the same as in Elixir. Pipe operator pipes result in the previous function as the last parameter of the next function.
Originally published at https://blog.tentamen.eu on November 20, 2020.