๐ชฑList and tuples
Lists
iex(1)> x = [1, 2, 3, 4]
[1, 2, 3, 4]iex(2)> x = ["hi", 1, true, :atom]
["hi", 1, true, :atom]Common list operations
iex(3)> [1, 2] ++ [4, 5]
[1, 2, 4, 5]
iex(4)> [1, 2, 3] -- [2, 3]
[1]iex(5)> hd([1, 2, 3])
1
iex(6)> tl([1, 2, 3])
[2, 3]
iex(7)> hd([])
** (ArgumentError) errors were found at the given arguments:
* 1st argument: not a nonempty list
:erlang.hd([])
iex:7: (file)Tuples
Lists or tuples?
Comparing lists and tuples
Last updated