Flow

Since the early days, Elixir has allowed us to easily process collections using the Enum and Stream modules. In the first case, the collection is traversed as soon as it reaches an Enum call, if we use the respective Stream function instead, we can delay the actual enumeration of the collection until the very last moment. This is why we say Stream functions are lazy and Enum functions are eager.

As a result, if we transform a collection by chaining Enum.map/2 calls, an intermediate collection will be created for each call to an Enum function. This behavior contrasts with the behavior we would get if we chained a bunch of Stream.map/2 calls. In the latter case, the entire collection would be traversed at most once, and only when the resulting ...

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