Occasionally I run into a situation where I want to pass a tuple around to group some data. However the language currently does not support to destructure a statically known tuple of fixed length.
It would be great if the language gained such capability.
# before
X := SomeTuple(0)
Y := SomeTuple(1)
# after
(X, Y) := SomeTuple # `tuple` is of type `tuple(T1, T2)`
Having it for tuples is great, but we could go even further in the future. We could permit other assignment destructuring for other structures such as arrays, structs etc.
foo := struct {
A: int
B: int
C<private>: int = 42
}
# Does not extract `C` as it's not visible from this scope.
(A, B) := foo { A := 1, B := 2 }
[First, Second] := [1, 2]
[First, Second, ...Rest] := [10, 20, 30, 40, 50]