iyi

Playground · Data · 20 of 33

tuples

Tuples: a fixed group of values, each with its own type.

samples/tour/tuples.iyi · tuples.wasm · 124 KB
# Tuples: a fixed group of values, each with its own type.

pair = {1, "one"}
puts pair[0]
puts pair[1]

# Unpack into variables.
number, word = pair
puts "#{number} is #{word}"

# A named tuple gives each slot a name.
person = {name: "Ayşe", age: 31}
puts person[:name]
puts person[:age]

# A function that answers several things at once.
def min_max(items : Array(Int32)) : Tuple(Int32, Int32)
  low = items.first
  high = items.first
  items.each do |n|
    low = n if n < low
    high = n if n > high
  end
  {low, high}
end

low, high = min_max([7, 2, 9, 4])
puts "#{low}..#{high}"
output
Press Run.

recorded with iyi 0.18.0 (built on Crystal 1.22.0-dev [2a9653052] (2026-10-18)) · Linux 7.0.0-38-generic x86_64, QEMU Virtual CPU version 2.5+ · 2026-10-19

You can type in the pane: nothing here compiles, so what you type cannot run, and the page says which bytes it is running the moment the text stops being the recorded file. There is no standard input, no filesystem and no threads on this target, and one sample fails on purpose for exactly that reason.

Run executes tuples.wasm, the module the compiler built from this file, in your browser. How this works

Try it on your machine

Copy the program into tuples.iyi, change something, and run it. Only a compiler on your own machine can run what you wrote.

sh, after installing
$ iyi run tuples.iyi