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 ...

Get Learn Functional Programming with Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.