6. Types
Value types Collection types
Arbittrary‑sized integers Tuples
Floating‑point numbers Lists
Atoms Maps
Ranges Binaries
Regular expressions
number < atom < tuple < map < list < binary
6
7. Immutability
‑ All values are Immutable
‑ Copying Data
iex> list1 = [3, 2, 1]
[3, 2, 1]
iex> list2 = [4 | list1]
[4, 3, 2, 1]
7
8. Pattern Matching (1/2)
Not an assignment
iex> a = 1
1
iex> 1 = a
1
iex> 2 = a
** (MatchError) no match of right hand side value: 1
More Complex Matches
iex> list = [1, 2, 3]
[1, 2, 3]
iex> [a, 2, b] = list
[1, 2, 3]
iex> a
1
iex> b
3
8
9. Pattern Matching (2/2)
Variable Bind Once (per Match)
iex> [a, a] = [1, 1]
[1, 1]
iex> a
1
iex> [b, b] = [1, 2]
** (MatchError) no match of right hand side value: [1, 2]
pin operator: ^
iex> a = 8
8
iex> [^a, 2] = [1, 2]
** (MatchError) no match of right hand side value: [1, 2]
9
11. Modules and Named Functions (1/2)
Function Calls and Pattern Matching
defmodule Factorial do
def of(0), do: 1
def of(n), do: n * of(n ‐ 1)
end
Guard Clauses
defmodule Factorial do
def of(0), do: 1
def of(n) when n > 0 and is_integer(n) do
n * of(n ‐ 1)
end
end
11
12. Modules and Named Functions (2/2)
Default Parameters
defmodule Example do
def func(p1, p2 2) do
IO.inspect [p1, p2]
end
end
Private Functions
defmodule Factorial do
defp foo(a): do: false
end
12
20. Intro
Chris McCord (@chris_mccord)
v1.0.0 ‑ Aug 28, 2015
server‑side MVC pattern, like Rails / Django
high developer productivity and high application performance
channels for implementing realtime features
Final results from Phoenix channel benchmarks on
40core/128gb box. 2 million clients, limited by ulimit
‑ Tweet from @chris_mccord
20