liveBook · Manning

Enumerable property

As explained in Elixir in Action, Third Edition

An enumerable is a data structure or abstraction that implements the contract required for traversal by Enum operations.

An enumerable is a data structure that implements the contract required by Enum operations. It lets iteration helpers hide recursive and tail-recursive boilerplate behind concise calls. section 3.4.3

Common enumerable operations include:

  • Enum.each/2 visits every element and applies a function. section 3.4.3
  • Enum.map/2 transforms each element into a new enumerable result. section 3.4.3
  • Enum.filter/2 retains elements matching a predicate, while Enum.reduce/3 accumulates a result. section 3.4.3
  • Lists, ranges, maps, and MapSet are examples; custom data structures can also implement the required contract. section 3.4.3

Traversing an enumerable

Enum.each([1, 2, 3], fn x -> IO.puts(x) end) prints each element without explicit recursion. section 3.4.3

How Elixir in Action, Third Edition covers it

How deep it goes
Defines the contract and examples but defers the full contract details to later treatment.
Examples
Uses Enum.each/2, Enum.map/2, Enum.filter/2, and Enum.reduce/3 with lists and other enumerable structures.
What it assumes
Assumes familiarity with lambdas and Enum.each/2 while postponing the complete enumerable contract explanation.
What you can do after
Apply it via Enum.each/2, Enum.map/2, Enum.filter/2, and Enum.reduce/3 without writing traversal recursion.
How it connects
Connects Enum operations with higher-order functions, recursion, lists, ranges, maps, and MapSet.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.