How can we write to a parameter-pack tuple with the iteration syntax?

I think for now you're limited to an all-at-once functional solution.

It's not obvious from documentation, but you can call function on each element. In example below, I map simple { $0 + 1 } closure on each member of tuple.

Maybe something like this could meet your needs.

func myFunction<each T: FixedWidthInteger>(_ t: repeat each T) -> (repeat each T) {

    return (repeat { $0 + 1 }(each t) )
}

// Prints:
//   (2, 3, 4, 5)
let result = myFunction(1, 2, 3, 4)
print(result)
2 Likes