Nested Dictionary Structures
The various dictionary types let us associate keys with values. But those values can themselves be dictionaries. For example, we may have a bug-reporting system. We could represent this using the following:
| defmodule Customer do |
| defstruct name: "", company: "" |
| end |
| |
| defmodule BugReport do |
| defstruct owner: %Customer{}, details: "", severity: 1 |
| end |
Let’s create a simple report:
| iex> report = %BugReport{owner: %Customer{name: "Dave", company: "Pragmatic"}, |
| ...> details: "broken"} |
| %BugReport{details: "broken", severity: 1, |
| owner: %Customer{company: "Pragmatic", name: "Dave"}} |
The owner attribute of the report is itself a Customer struct. ...
Get Programming Elixir ≥ 1.6 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.