4  Tuples

Tuples are often used as function arguments or return values

a = ("super", 99)
("super", 99)
typeof(a)
Tuple{String, Int64}

4.1 Named Tuples

a = (fruit = "mango", number = 1)
(fruit = "mango", number = 1)
typeof(a)
@NamedTuple{fruit::String, number::Int64}

4.1.1 Create Named Tuple from separate tuples/arrays of keys and values

Keys = (:Key1, :Key2, :Key3)
Values = (3, 5, 7)
(3, 5, 7)
x = (; zip(Keys, Values)...)
(Key1 = 3, Key2 = 5, Key3 = 7)
typeof(x)
@NamedTuple{Key1::Int64, Key2::Int64, Key3::Int64}
Keys = [:One, :Two, :Three]
Vals = [11, 13, 17]
3-element Vector{Int64}:
 11
 13
 17
z = (; zip(Keys, Values)...)
(One = 3, Two = 5, Three = 7)

4.2 Resources