Skip to content

Instantly share code, notes, and snippets.

@Varriount
Created February 1, 2014 05:14
Show Gist options
  • Save Varriount/8748313 to your computer and use it in GitHub Desktop.
Save Varriount/8748313 to your computer and use it in GitHub Desktop.
Use varargs for even more awesomeness!
iterator transpose[T](groups: seq[seq[T]]): seq[T] =
let maxLen = groups[0].len - 1
for i in 0..maxLen:
var selection: seq[T] = @[]
for group in groups:
selection.add(group[i])
yield selection
when isMainModule:
var foo = @[@[1,2,3,4],@[5,6,7,8],@[9,10,11,12]]
for z in transpose(foo):
echo(repr(z))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment