I'm a newbie but I think it is very 'Nim' to make an iterator:
iterator columns*[T](mat: seq[seq[T]]): seq[T] =
var col = newSeq[T](mat.len)
for c in 0..<mat[0].len:
for r in 0..<mat.len:
col[r] = mat[r][c]
yield col
Run
and then you can do:
let v = @[@[2, 4, 1], @[2, 0, 2], @[1, 1, 2], @[0, 0, 0]]
for i in columns(v):
echo i
@[2, 2, 1, 0]
@[4, 0, 1, 0]
@[1, 2, 2, 0]
Run
