Home

Elixir Maps & Structs

tl;dr

Maps

iex> map = %{a: 1, b: 2} %{a: 1, b: 2} iex> map[:a] 1 iex> %{map | a: 3} %{a: 3, b: 2}

Structs

Defining it in the Elixir REPL:

iex> defmodule User do ...> defstruct name: "John", age: 27 ...> end iex> %User{} %User{age: 27, name: "John"} iex> %User{name: "Jane"} %User{age: 27, name: "Jane"}

Repository

https://github.com/okeeffed/developer-notes-nextjs/content/elixir/elixir-maps-and-structs

Sections


Related