Stream processing and Elixir
Since Elixir is functional, stream processing in Elixir is quite simple. We have functions such as Enum.map/2
, Enum.filter/2
, and Enum.reduce/2
. Further still, we have a way to express computations inherently as flows, even if we are not (yet) completely taking advantage of flow-based programming.
Simply, the |>
operator is a way to express program flow as you read it. Rather than awkwardly writing programs inside out or right to left, we can express our computation naturally from left to right. Let's begin to examine some simple examples of this.
Quickly, let's take a look at our map/2
function from earlier chapters:
iex(1)> defmodule MyMap do ...(1)> def map([], _), do: [] ...(1)> def map([h|t], f), do: [f.(h) | map(t, f)] ...(1)> end {:module, MyMap, <<70, 79, 82, 49, 0, 0, 4, 220, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 130, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0...