Tuples, Maps and Records
- Tuples. A tuple groups fixed fields: {ok, Value} and {error, Reason} are the languageās handshake.
- Maps. A map holds key-value data: #{name => <<"Ada">>}: matched with := on known keys.
- Records. A record is compile-time sugar over tuples: named fields for module-internal structure.
Guards
- Guards. A guard refines a match: when X > 0: from a restricted, side-effect-free set of tests.
- Guard sequences. Guards combine with comma (and) and semicolon (or): compact truth tables on clauses.
- Guards versus function calls. Only built-in tests may guard: your own functions cannot, by design, so guards stay pure.
Advanced Pattern Matching
- Binaries. The binary syntax matches bytes: <<Len:16, Body:Len/binary>>: protocol parsing as patterns.
- Nested matching. Patterns nest deep: {user, #{address := #{city := City}}}: one line reaching inside.
- Match in every seam. Erlang matches everywhere: function heads, case, receive: one mechanism across the whole language.
Before and after this level
- Before: Level 2: Functional Erlang: Recursion, Lists and Higher-Order Functions, Immutable Data Transformation.
- Next: Level 4: Processes: Lightweight Processes, Message Passing, Mailboxes and Receive.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Erlang Level 3: Data & Pattern Matching cover?
Tuples, Maps and Records, Guards, Advanced Pattern Matching: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 2: Functional Erlang, which covers Recursion, Lists and Higher-Order Functions, Immutable Data Transformation.