We cover:

  • The Enum module
  • The Stream module
  • The Collectable protocol
  • Comprehensions

Chapter 10Processing Collections—Enum and Stream

Elixir comes with a number of types that act as collections. We’ve already seen lists and maps. Ranges, files, and even functions can also act as collections. 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 collections. You’ll ...

Get Programming Elixir ≥ 1.6 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.