Pipelining Your Functions
Elixir has the famous pipe operator that’s useful for combining functions to achieve a greater goal. It has a delightful syntax to execute many functions in sequence, and it’s easy to read and understand. Other functional languages have a higher-order function that can compose functions. Elixir doesn’t have a built-in function or an operator for function composition, but we can create it ourselves by using the pipe operator to combine two functions. Function composition and the pipe operator are useful for creating maintainable code by combining many small and focused routines. Let’s see them in action, and you’ll understand why you should prefer the pipe operator.
First, let’s create a function that composes functions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access