Lists
import IEx.Helpers
Idiomatic Elixir
- sequential (enumerable)
- like datatypes
- acceptable for short or long
- access head first
Syntax
list = [1, 2, 3]
[1, 2, 3]
[19, 0 | list]
# | -> list append operator
[19, 0, 1, 2, 3]
Match
[head | tail] = list
[1, 2, 3]
head
1
tail
[2, 3]
[one, two | rest] = [1, 2]
{one, two, rest}
{1, 2, []}
{[first | _], _, _} = {[1, 2, 3], 4, 5}
{[1, 2, 3], 4, 5}
first
1