liveBook · Manning

Pure functional data structure

As explained in Elixir in Action, Third Edition

A pure functional data structure is an immutable data structure whose operations produce new values without modifying existing values.

A pure functional data structure models data with immutable values: operations return transformed values instead of modifying existing state. This preserves integrity, atomicity, reusability, and testability. section 5.3.4

Keep the data structure separate from the stateful process that owns it. The process stores the current value, applies requests sequentially, and replaces its state with each returned value. This avoids using processes merely to simulate mutable data while preserving serialized access to shared state. section 5.3.4

Todo list state

Build a TodoList by chaining add_entry calls, then query entries for a date. A TodoServer can keep that value alive, delegate operations to TodoList, and continue its loop with the returned list. section 5.3.4

How Elixir in Action, Third Edition covers it

How deep it goes
Explains benefits and process integration, but defers the underlying TodoList implementation details.
Examples
Uses a TodoList with chained additions, date queries, and a TodoServer that delegates requests.
What it assumes
Assumes familiarity with processes and functional programming while reinforcing immutable state transformation.
What you can do after
Build it from scratch as an immutable data layer behind a stateful process API.
How it connects
Connects immutable data structures with processes, concurrency, serialization, and web-server scalability.

Also explained in

Compare how 2 books explain pure functional data structure →

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.