Enumerating Data Structures

You’ll perform two types of operations on your data. Iteration reads the contents of the data structure, so you can do something meaningful with it. Map (or reduce) transforms the contents of the data structure to modify it or to create something totally different.

Elixir has several options for iterating and mapping your data structures. We’re going to look at a few of the built-in options that Elixir gives for iteration and mapping. We’ll cover the Enum module and comprehensions.

Enum Module

The Enum[29] module is arguably the most useful module in the standard library. It does lots of things, but we’ll cover some of the most commonly used functions. It’s built on top of the Enumerable protocol, which lets us enumerate ...

Get From Ruby to 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.