Maps and Structs
Let’s learn about some of the properties of maps and structs in Elixir.
We'll cover the following...
We'll cover the following...
Introduction
The map has rapidly become the go-to data structure for Elixir programmers. For this lesson, we’re going to treat maps and structs as basically the same thing. In iex
, we can see that a struct is implemented as a map. Let’s take a peek under the hood by running the following commands in the iex
terminal:
Executable
Press + to interact
defmodule User dodefstruct [:name, :email]end
Press + to interact
map = %User{}
Press + to interact
is_map(map)
Press + to interact
map.__struct__
Output
iex(1)> defmodule User do
...(1)> defstruct [:name, :email]
...(1)> end
{:module, User, . . . }
iex(2)> map = %User{}
%User{email: nil, name:
...