The Tuple Type is a fixed size type (i.e.: we cannot remove or add values from/to a tuple) that groups together values of miscellaneous types.
Tuples are declared using parenthesis, and commas to separate values:
let t = (5, 'h', 11.7);
t(5, 'h', 11.7)To declare explicitly the types of the values, we use a tuple of types:
let u: (i8, f32, char) = (34, 78.56, 'a');
u(34, 78.56, 'a')The values of a tuple are indexable:
let t = (5, 'h', 11.7);
t.211.7We may decompose an existing tuple, by using a tuple of variables inside the
let declaration. Some values may be ignored by using the _ (underscore)
notation:
let t = (5, 'h', 11.7);
let (_, c, _) = t;
c'h'