Simple Functions

Phoenix is built on Elixir, which is a beautiful language, so we’re going to use Elixir to talk about the way the layers of Phoenix fit together. In Elixir, we might have a couple of functions like these:

 def​ inc(x), ​do​: x + 1
 def​ dec(x), ​do​: x - 1

We can chain together several different function calls like this:

 2 |> inc |> inc |> dec

The |>, or pipe operator, takes the value on the left and passes it as the first argument to the function on the right. We call these compositions pipes or pipelines, and we call each individual function a segment or pipe segment.

There’s a side benefit, though. Pipelines are also functions. That means you can make pipelines of pipelines. This idea will help you understand how the ...

Get Programming Phoenix 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.