proc fillTuple[T: tuple, V](target: var T, input: openarray[V]) = var index = 0 for field in target.fields: assert input.len > index field = input[index] inc(index) var myTuple: tuple[a,b,c: int] fillTuple(myTuple, @[1, 2, 3])
Or, if you want the tuple as return value: proc fillTuple[T: tuple, V](input: openarray[V]): T = var index = 0 for field in result.fields: assert input.len > index field = input[index] inc(index) var myTuple = fillTuple[tuple[a,b,c:int], int](@[1, 2, 3])