I saw this in Swift's blog, in an article about pack iteration:
func allEmpty<each T>(_ array: repeat [each T]) -> Bool {
for a in repeat each array {
guard a.isEmpty else { return false }
}
return true
}
These just read (parts of) the arguments. What if I wanted to mutate each variadic member? Could I use "a
"? What about using "array
" within the block?
My actual example using an iterator (IteratorProtocol
) storing several iterators. The initializer uses the pack for generating each parameter. The internal storage uses the pack to define members of a tuple. So I need the top-layer "next
" to call all the inner ones.