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

  1. Create point = {3, 4} and print it → (3, 4)
  2. Create person = %{name: "Alice", age: 30}
  3. Print person.nameAlice
  4. Print person.age30
JS Transpiler loading...
Loading...
Click "Run" to execute your code.