A lazy enumerable computes values on demand instead of producing the result immediately. In Elixir, Stream functions build a computation structure; an Enum function triggers iteration. section 3.4.5
This changes both performance and control flow:
- Compose transformations without creating intermediate lists, allowing multiple operations in one pass. section 3.4.5
- Let a consumer such as Enum.to_list, Enum.each, or Enum.take request values and determine how far iteration proceeds. section 3.4.5
Streaming a file pipeline
File.stream! can feed lines through trimming and filtering while avoiding an eagerly built intermediate result. The same pattern supports filtering, mapping, indexing, and printing in a single pipeline.
