Reputation: 831
After doing some research, I have not been able to find any concrete confirmation, but it seems as though the Generator associated type of the sequence protocol has been renamed to iterator. Is this correct?
I cant find anything on the swift API reference about the protocol GeneratorType or the associated type Generator. I'm only seeing people write about it on blogs.
So my question is do generators and iterators refer to the exact same concept in swift?
Upvotes: 0
Views: 915
Reputation: 80811
Do generators and iterators refer to the exact same concept in Swift?
In a word; yes.
As said in the evolution proposal for the Swift 3 'renamification' of the standard library:
Strip
Type
suffix from protocol names. In a few special cases this means adding aProtocol
suffix to get out of the way of type names that are primary [...].The concept of generator is renamed to iterator across all APIs.
As a consequence, the GeneratorType
protocol has been renamed to IteratorProtocol
.
The SequenceType
protocol was renamed to Sequence
, and went from looking like this:
public protocol SequenceType {
associatedtype Generator : GeneratorType
// ...
func generate() -> Generator
// ...
}
to looking like this:
public protocol Sequence {
associatedtype Iterator : IteratorProtocol
// ...
func makeIterator() -> Iterator
// ...
}
Upvotes: 2