Chapter 10Processing Collections—Enum and Stream

  • The Enum module

  • The Stream module

  • The Collectable protocol

  • Comprehensions

Elixir comes with a number of types that act as collections. We’ve already seen lists and dictionaries. There are also things such as ranges, files, dictionaries, and even functions. And as we’ll discuss when we look at protocols, you can also define your own.

Collections differ in their implementation. But they all share something: you can iterate through them. Some of them share an additional trait: you can add things to them.

Technically, things that can be iterated are said to implement the Enumerable protocol.

Elixir provides two modules that have a bunch of iteration functions. The Enum module is the workhorse for ...

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