Stream is Elixir’s lazy enumerable for composing transformations without immediately traversing or materializing the input. Stream.map/2, filter/2, and with_index/2 build a computation; an Enum function such as each/2, take/2, or to_list/1 realizes it. This can combine indexing and output in one pass instead of creating an intermediate list. section 3.4.5
Use streams when a pipeline benefits from deferred, composable iteration:
- Compose Stream.filter/2, Stream.map/2, and Stream.with_index/2, then terminate with Enum.each/2 or another Enum function. section 3.4.5
Import and transform a CSV file
A file-import pipeline can stream lines, remove trailing newlines, split each line into date and title, convert the date, and construct to-do entries before passing the resulting enumerable to TodoList.new/1. Build it incrementally and inspect each intermediate result; once the eager version works, replace suitable Enum operations with Stream functions. section 4.2.5
