Created
February 1, 2014 05:14
-
-
Save Varriount/8748313 to your computer and use it in GitHub Desktop.
Use varargs for even more awesomeness!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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