> But if you do this you will get a different compiler error, because your 
> struct will no longer conform to Sequence, which requires makeIterator to be 
> non-mutating. This is important, especially assuming your array is eventually 
> going to conform to Collection as well. One of the requirements of 
> collections is that they give an accurate count, but in the case of your 
> array, the count returned might be different (greater) than the number of 
> elements returned when you actually iterate the array, and this is not 
> allowed (you may find that some standard library functions will trap when 
> they discover that this has happened).

Btw, isn’t it strange that the next() method in `IteratorProtocol` *is* 
mutating, and makeIterator() is not?

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to