[swift-users] inout generic struct parameter error

Ben Cohen ben_cohen at apple.com
Mon Jan 2 18:59:39 CST 2017


> On Jan 2, 2017, at 1:52 AM, Georgios Moschovitis <george.moschovitis at icloud.com> wrote:
> 
> Btw, isn’t it strange that the next() method in `IteratorProtocol` *is* mutating, and makeIterator() is not?

Iterators are inherently stateful things. But for collections, the state they are mutating is their own progress through the collection as you iterate – they aren’t mutating the collection itself. That is what their mutating keyword on next() is indicating. On the other hand, creating a fresh one from the collection by calling makeIterator() shouldn’t need to mutate the collection.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170102/dfb1e1b8/attachment.html>


More information about the swift-users mailing list