Lesson 13 of 16
Tuples & Maps
Tuples
Tuples are fixed-size ordered collections, created with {}:
point = {3, 4}
IO.puts(point) # (3, 4)
Destructure them with pattern matching:
{x, y} = {3, 4}
IO.puts(x) # 3
Maps
Maps store key-value pairs with %{}:
person = %{name: "Alice", age: 30}
IO.puts(person.name) # Alice
IO.puts(person.age) # 30
Your Turn
- Create
point = {3, 4}and print it →(3, 4) - Create
person = %{name: "Alice", age: 30} - Print
person.name→Alice - Print
person.age→30
JS Transpiler loading...
Loading...
Click "Run" to execute your code.