/elixir-phoenix-learn

This repository contains source code and notes related to my own personal learning of the Elixir programming language and the Phoenix framework.

Primary LanguageElixir

Elixir learn

This repository contains source code related to my own personal learning of the Elixir programming language and the Phoenix framework.

Projects in the repo

Study Notes

Keyword Lists

Creates a new keyword list and access a property

iex> colors = [{:primary, "red"}, {:secondary, "blue"}]
iex> colors[:secondary]
"blue"

Maps

Creating a map and accessing its values directly

iex> colors = %{ primary: "red", secondary: "blue" }
iex> colors.secondary 
"blue"

Using pattern matching with a map

iex> colors = %{ primary: "red", secondary: "blue" }
iex> %{secondary: secondary_color} = colors
iex> secondary_color
"blue"

Update a value in a map using a function of the Map type

iex> colors = %{ primary: "red", secondary: "blue" }
iex> Map.put(colors, :primary, "yellow")
%{primary: "yellow", secondary: "blue"}

Update a value in a map using the pipe | symbol

iex> colors = %{ primary: "red", secondary: "blue" }
iex> %{ colors | primary: "yellow" }
%{primary: "yellow", secondary: "blue"}

Put a new value to an existing map

iex> colors = %{ primary: "red" }
iex> Map.put_new(colors, :secondary, "blue")
%{primary: "red", secondary: "blue"}

Useful commands

IEx (interactive shell)

Run interactive shell

$ iex -S mix

Mix (build tool)

Get dependencies

$ mix deps.get

Generate documentation

$ mix docs

Execute tests

$ mix test