2. Is there any way to iterate multiple collections simultaneously, like with python:
for x, y in zip(xs, ys):
...
As far as I know, there is no zip analog in standard library. How can I implement it myself?
let s = @[(1, false, "abc"), (2, true, "def")]
for num, bo, str in items(s):
echo num, ' ', bo, ' ', str
actually, this code works for your example:
iterator zip[A,B](a:seq[A], b:seq[B]) : tuple[a:A,b:B] =
for i in 0 .. min(len(a), len(b))-1:
yield (a[i], b[i])
let
xs = @[1,2,3,4]
ys = @["a", "b", "c", "d"]
for x,y in zip(xs,ys):
echo x, y