May 2018
Intermediate to advanced
412 pages
9h 3m
English
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. ...
Read now
Unlock full access