Search⌘ K
AI Features

Functional Data Structures

Explore functional data structures within Elixir systems, focusing on immutability and transaction-based balance calculation. Understand how to design consistent data layers that avoid race conditions and maintain accuracy across concurrent processes.

Writing data structures functionally

Let’s keep exploring our bank account example. Here’s one way to think about it:

account:
%{
     account_number: String, 
     account_holder: %User{},
     balance: Int, 
     transaction_log: [strings],
 }

This structure works fine in many languages, but it is not a functional data structure. There’s a hidden problem. Let’s examine a quick hypothetical example.

Processes are not data

Since we’re writing an Elixir program, it’s tempting to wrap this data in a process and allow ...