swift repl:
zip([1,2,3],[7,8,9]).generate().next()
repl.swift:1:22: error: value of type \'Zip2Generator>, Index
The function next()
mutates the object that it is called on, so that object must be assigned to a var
for it to work. zip([1,2,3],[7,8,9]).generate()
is immutable until you assign it to a var
.
Why does next()
mutate the object? Because there is an internal index variable that is keeping track of which value to show next. next()
uses that internal index and then advances it (mutates it) to point to the next item.