-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Current situation
To iterate through a container, we now have:
for val in mySeq:
...There is also an option to have an index too with:
for i, val in mySeq:
...If mySeq is container of tuples, we currently need to do:
for val in mySeq:
let
x = val[0]
y = val[1]
z = val[2]
...An example of zip usage:
for val in zip(seqA, seqB):
let area = val.a * val.b # you must use `a` and `b`, no other letters/wordsProposal
My proposition is to have tuple unpacking available in loops, and to use the same syntax which is currently used for tuple unpacking in let statements: let (x, y, z) = myTuple.
The above example now looks like this:
for (x, y, z) in mySeq:
...or if you want to also use an index:
for i, (x, y, z) in mySeq:
...The example with zip would now allow more meaningful names:
for (length, height) in zip(seqA, seqB):
let area = length * heightParentheses must be used to make a clear, understandable difference between for i, val in mySeq and for (x, y) in mySeq, where i is an index, val is a whole tuple, and x and y are elements of that tuple.
This would allow to have a cleaner, nicer and more readable code.
Thoughts?