0Pricing
Elixir & Phoenix: Scalable Backend Development · Lesson

Lazy Evaluation with the Stream Module

Process large or infinite collections efficiently using Elixir streams, which compute values lazily on demand.

Eager vs Lazy

Enum is eager: each step builds a full intermediate list. Stream is lazy: it composes operations and computes only when needed.

The Cost of Eager Pipelines

Chaining several Enum calls walks the whole collection multiple times and allocates a list at each stage.

1..1_000_000
|> Enum.map(&(&1 * 2))
|> Enum.filter(&(rem(&1, 3) == 0))
|> Enum.take(5)
|> IO.inspect()

All lessons in this course

  1. Functions, Modules, and Pipelining
  2. Working with Enumerable Collections
  3. Recursion and Higher-Order Functions
  4. Lazy Evaluation with the Stream Module
← Back to Elixir & Phoenix: Scalable Backend Development