Skip to content

Commit 1c00478

Browse files
gribozavrMax Moiseev
authored and
Max Moiseev
committed
Rename SequenceType.generate() to SequenceType.iterator()
1 parent 2cf1721 commit 1c00478

File tree

93 files changed

+392
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+392
-392
lines changed

docs/SequencesAndCollections.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ represented by the `SequenceType` protocol::
3737

3838
protocol SequenceType {
3939
typealias Iterator : IteratorProtocol
40-
func generate() -> Iterator
40+
func iterator() -> Iterator
4141
}
4242

4343
.. sidebar:: Hiding Iterator Type Details
@@ -68,8 +68,8 @@ the two kinds of sequences.
6868
\ `in`, and thus require *separate traversal state*.
6969

7070
To get an initial traversal state for an arbitrary sequence `x`, Swift
71-
calls `x.generate()`. The sequence delivers that state, along with
72-
traversal logic, in the form of a **iterator**.
71+
calls `x.iterator()`. The sequence delivers that state, along with
72+
traversal logic, in the form of an **iterator**.
7373

7474
Iterators
7575
==========
@@ -160,10 +160,10 @@ end. For example::
160160
withSeparator separator: S.Iterator.Element
161161
) -> [S.Iterator.Element] {
162162
var result: [S.Iterator.Element] = []
163-
var g = source.generate()
164-
if let start = g.next() {
163+
var iterator = source.iterator()
164+
if let start = iterator.next() {
165165
result.append(start)
166-
while let next = g.next() {
166+
while let next = iterator.next() {
167167
result.append(separator)
168168
result.append(next)
169169
}
@@ -192,7 +192,7 @@ depend on stability that an arbitrary sequence can't provide:
192192
the elements it has yet to return from `next()`. Therefore, every
193193
iterator *could* satisfy the requirements of `SequenceType` by
194194
simply declaring conformance, and returning `self` from its
195-
`generate()` method. In fact, if it weren't for `current language
195+
`iterator()` method. In fact, if it weren't for `current language
196196
limitations <rdar://17986597>`_, `IteratorProtocol` would refine
197197
`SequenceType`, as follows:
198198

docs/archive/LangRef.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ <h4 id="protocol-member-typealias">'typealias' protocol elements (associated typ
626626
<pre class="example">
627627
protocol SequenceType {
628628
typename Iterator : IteratorProtocol
629-
func generate() -> Iterator
629+
func iterator() -> Iterator
630630
}
631631
</pre>
632632

docs/proposals/DeclarationTypeChecker.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ We can address this problem by restricting the language to disallow extensions v
8080

8181
protocol SequenceType {
8282
typealias Element
83-
mutating func generate() -> Element?
83+
mutating func iterator() -> Element?
8484
}
8585

8686
struct IntRangeGenerator : SequenceType {
8787
var current: Int
8888
let limit: Int
8989

9090
// infers SequenceType's Element == Int
91-
mutating func generate() -> Int? {
91+
mutating func iterator() -> Int? {
9292
if current == limit { return nil }
9393
return current++
9494
}

include/swift/AST/KnownIdentifiers.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ IDENTIFIER(error)
3636
IDENTIFIER(forKeyedSubscript)
3737
IDENTIFIER(Foundation)
3838
IDENTIFIER(fromRaw)
39-
IDENTIFIER(generate)
4039
IDENTIFIER(hashValue)
4140
IDENTIFIER(init)
41+
IDENTIFIER(iterator)
4242
IDENTIFIER(Iterator)
4343
IDENTIFIER(load)
4444
IDENTIFIER(next)

lib/Sema/TypeCheckStmt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
599599
S->setSequence(sequence);
600600
}
601601

602-
// Invoke generate() to get a generator from the sequence.
602+
// Invoke iterator() to get an iterator from the sequence.
603603
Type generatorTy;
604604
VarDecl *generator;
605605
{
@@ -620,7 +620,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
620620

621621
Expr *getIterator
622622
= TC.callWitness(sequence, DC, sequenceProto, conformance,
623-
TC.Context.Id_generate,
623+
TC.Context.Id_iterator,
624624
{}, diag::sequence_protocol_broken);
625625
if (!getIterator) return nullptr;
626626

stdlib/private/StdlibUnittest/CheckCollectionType.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ extension TestSuite {
333333
testNamePrefix += String(Collection.Type)
334334

335335
//===----------------------------------------------------------------------===//
336-
// generate()
336+
// iterator()
337337
//===----------------------------------------------------------------------===//
338338

339-
self.test("\(testNamePrefix).generate()/semantics") {
339+
self.test("\(testNamePrefix).iterator()/semantics") {
340340
for test in subscriptRangeTests {
341341
let c = makeWrappedCollection(test.collection)
342342
for _ in 0..<3 {

stdlib/private/StdlibUnittest/LoggingWrappers.swift.gyb

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ public struct LoggingRangeReplaceableCollection<
226226
return try base.filter(includeElement)
227227
}
228228

229-
public func generate() -> Base.Iterator {
230-
return base.generate()
229+
public func iterator() -> Base.Iterator {
230+
return base.iterator()
231231
}
232232
}
233233

@@ -447,9 +447,9 @@ public struct Logging${Kind}<Base: ${Kind}Type> : ${Kind}Type, LoggingType {
447447
}
448448
% end
449449

450-
public func generate() -> LoggingIterator<Base.Iterator> {
450+
public func iterator() -> LoggingIterator<Base.Iterator> {
451451
++Log.generate[selfType]
452-
return LoggingIterator(base.generate())
452+
return LoggingIterator(base.iterator())
453453
}
454454

455455
public func underestimateCount() -> Int {

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

+12-12
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ public func checkSequence<
19181918
) {
19191919
let expectedCount: Int = numericCast(expected.count)
19201920
checkIterator(
1921-
expected, sequence.generate(), ${trace},
1921+
expected, sequence.iterator(), ${trace},
19221922
resiliencyChecks: resiliencyChecks,
19231923
sameValue: sameValue)
19241924

@@ -2476,7 +2476,7 @@ func compose<A, B, C>(f: A -> B, _ g: B -> C) -> A -> C {
24762476
}
24772477

24782478
/// State that is created every time a fresh iterator is created with
2479-
/// `MinimalSequence.generate()`.
2479+
/// `MinimalSequence.iterator()`.
24802480
internal class _MinimalIteratorPrivateState<T> {
24812481
internal init() {}
24822482

@@ -2583,8 +2583,8 @@ extension StrictSequenceType {
25832583
}
25842584

25852585
extension StrictSequenceType where Iterator : _MinimalIteratorProtocol {
2586-
public func generate() -> MinimalIterator<Element> {
2587-
return base.generate()
2586+
public func iterator() -> MinimalIterator<Element> {
2587+
return base.iterator()
25882588
}
25892589
}
25902590

@@ -2615,7 +2615,7 @@ public struct MinimalSequence<T> : SequenceType, CustomDebugStringConvertible {
26152615
}
26162616
}
26172617

2618-
public func generate() -> MinimalIterator<T> {
2618+
public func iterator() -> MinimalIterator<T> {
26192619
return MinimalIterator(_sharedState)
26202620
}
26212621

@@ -3332,8 +3332,8 @@ extension ${Protocol} {
33323332
}
33333333

33343334
extension ${Protocol} where Iterator : _MinimalIteratorProtocol {
3335-
public func generate() -> MinimalIterator<Element> {
3336-
return base.generate()
3335+
public func iterator() -> MinimalIterator<Element> {
3336+
return base.iterator()
33373337
}
33383338
}
33393339

@@ -3386,7 +3386,7 @@ public struct ${Self}<T> : ${'MutableCollectionType' if mutable else 'Collection
33863386
}
33873387
}
33883388

3389-
public func generate() -> MinimalIterator<T> {
3389+
public func iterator() -> MinimalIterator<T> {
33903390
return MinimalIterator(_elements)
33913391
}
33923392

@@ -3461,8 +3461,8 @@ extension ${Protocol} {
34613461
}
34623462

34633463
extension ${Protocol} where Iterator : _MinimalIteratorProtocol {
3464-
public func generate() -> MinimalIterator<Element> {
3465-
return base.generate()
3464+
public func iterator() -> MinimalIterator<Element> {
3465+
return base.iterator()
34663466
}
34673467
}
34683468

@@ -3531,7 +3531,7 @@ public struct ${Self}<T> : RangeReplaceableCollectionType {
35313531
_CollectionState(newRootStateForElementCount: self.elements.count)
35323532
}
35333533

3534-
public func generate() -> MinimalIterator<T> {
3534+
public func iterator() -> MinimalIterator<T> {
35353535
return MinimalIterator(elements)
35363536
}
35373537

@@ -3917,7 +3917,7 @@ public struct Defaulted${traversal}RangeReplaceableSlice<Element>
39173917
base: Base(elements: elements))
39183918
}
39193919

3920-
public func generate() -> MinimalIterator<Element> {
3920+
public func iterator() -> MinimalIterator<Element> {
39213921
return MinimalIterator(Array(self))
39223922
}
39233923

stdlib/public/SDK/Foundation/Foundation.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ extension NSArray : SequenceType {
725725
/// Return an *iterator* over the elements of this *sequence*.
726726
///
727727
/// - Complexity: O(1).
728-
final public func generate() -> NSFastEnumerationIterator {
728+
final public func iterator() -> NSFastEnumerationIterator {
729729
return NSFastEnumerationIterator(self)
730730
}
731731
}
@@ -769,7 +769,7 @@ extension NSSet : SequenceType {
769769
/// Return an *iterator* over the elements of this *sequence*.
770770
///
771771
/// - Complexity: O(1).
772-
public func generate() -> NSFastEnumerationIterator {
772+
public func iterator() -> NSFastEnumerationIterator {
773773
return NSFastEnumerationIterator(self)
774774
}
775775
}
@@ -778,7 +778,7 @@ extension NSOrderedSet : SequenceType {
778778
/// Return an *iterator* over the elements of this *sequence*.
779779
///
780780
/// - Complexity: O(1).
781-
public func generate() -> NSFastEnumerationIterator {
781+
public func iterator() -> NSFastEnumerationIterator {
782782
return NSFastEnumerationIterator(self)
783783
}
784784
}
@@ -816,7 +816,7 @@ extension NSIndexSet : SequenceType {
816816
/// Return an *iterator* over the elements of this *sequence*.
817817
///
818818
/// - Complexity: O(1).
819-
public func generate() -> NSIndexSetIterator {
819+
public func iterator() -> NSIndexSetIterator {
820820
return NSIndexSetIterator(set: self)
821821
}
822822
}
@@ -942,7 +942,7 @@ extension NSDictionary : SequenceType {
942942
/// Return an *iterator* over the elements of this *sequence*.
943943
///
944944
/// - Complexity: O(1).
945-
public func generate() -> Iterator {
945+
public func iterator() -> Iterator {
946946
return Iterator(self)
947947
}
948948
}
@@ -951,7 +951,7 @@ extension NSEnumerator : SequenceType {
951951
/// Return an *iterator* over the *enumerator*.
952952
///
953953
/// - Complexity: O(1).
954-
public func generate() -> NSFastEnumerationIterator {
954+
public func iterator() -> NSFastEnumerationIterator {
955955
return NSFastEnumerationIterator(self)
956956
}
957957
}

stdlib/public/core/Algorithm.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public func max<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
7171
/// starting at zero, along with the elements of the underlying
7272
/// `Base`:
7373
///
74-
/// var g = EnumeratedIterator(["foo", "bar"].generate())
75-
/// g.next() // (0, "foo")
76-
/// g.next() // (1, "bar")
77-
/// g.next() // nil
74+
/// var iterator = ["foo", "bar"].enumerate()
75+
/// iterator.next() // (0, "foo")
76+
/// iterator.next() // (1, "bar")
77+
/// iterator.next() // nil
7878
///
7979
/// - Note: Idiomatic usage is to call `enumerate` instead of
8080
/// constructing an `EnumeratedIterator` directly.
@@ -123,8 +123,8 @@ public struct EnumeratedSequence<Base : SequenceType> : SequenceType {
123123
/// Returns an *iterator* over the elements of this *sequence*.
124124
///
125125
/// - Complexity: O(1).
126-
public func generate() -> EnumeratedIterator<Base.Iterator> {
127-
return EnumeratedIterator(_base: _base.generate())
126+
public func iterator() -> EnumeratedIterator<Base.Iterator> {
127+
return EnumeratedIterator(_base: _base.iterator())
128128
}
129129
}
130130

stdlib/public/core/Arrays.swift.gyb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ internal func _arrayAppendSequence<
12161216
>(
12171217
inout buffer: Buffer, _ newItems: S
12181218
) {
1219-
var stream = newItems.generate()
1219+
var stream = newItems.iterator()
12201220
var nextItem = stream.next()
12211221

12221222
if nextItem == nil {
@@ -1262,8 +1262,8 @@ public func == <Element : Equatable>(
12621262
return true
12631263
}
12641264

1265-
var streamLHS = lhs.generate()
1266-
var streamRHS = rhs.generate()
1265+
var streamLHS = lhs.iterator()
1266+
var streamRHS = rhs.iterator()
12671267

12681268
var nextLHS = streamLHS.next()
12691269
while nextLHS != nil {

stdlib/public/core/Character.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public struct Character :
188188
internal var _data: UInt64
189189
}
190190

191-
internal func generate() -> Iterator {
191+
internal func iterator() -> Iterator {
192192
return Iterator(data)
193193
}
194194

@@ -199,7 +199,7 @@ public struct Character :
199199
struct _SmallUTF16 : CollectionType {
200200
init(_ u8: UInt64) {
201201
let count = UTF16.measure(
202-
UTF8.self, input: _SmallUTF8(u8).generate(),
202+
UTF8.self, input: _SmallUTF8(u8).iterator(),
203203
repairIllFormedSequences: true)!.0
204204
_sanityCheck(count <= 4, "Character with more than 4 UTF-16 code units")
205205
self.count = UInt16(count)
@@ -209,7 +209,7 @@ public struct Character :
209209
u16 = u16 | UInt64($0)
210210
}
211211
transcode(
212-
UTF8.self, UTF16.self, _SmallUTF8(u8).generate(), output,
212+
UTF8.self, UTF16.self, _SmallUTF8(u8).iterator(), output,
213213
stopOnError: false)
214214
self.data = u16
215215
}

stdlib/public/core/Collection.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public protocol MutableIndexable {
7373
/// An *iterator* for an arbitrary *collection*. Provided `C`
7474
/// conforms to the other requirements of `Indexable`,
7575
/// `IndexingGenerator<C>` can be used as the result of `C`'s
76-
/// `generate()` method. For example:
76+
/// `iterator()` method. For example:
7777
///
7878
/// struct MyCollection : CollectionType {
7979
/// struct Index : ForwardIndexType { /* implementation hidden */ }
8080
/// subscript(i: Index) -> MyElement { /* implementation hidden */ }
81-
/// func generate() -> IndexingGenerator<MyCollection> { // <===
81+
/// func iterator() -> IndexingGenerator<MyCollection> { // <===
8282
/// return IndexingGenerator(self)
8383
/// }
8484
/// }
@@ -128,9 +128,9 @@ public protocol CollectionType : Indexable, SequenceType {
128128
typealias Iterator : IteratorProtocol = IndexingGenerator<Self>
129129

130130
// FIXME: Needed here so that the Iterator is properly deduced from
131-
// a custom generate() function. Otherwise we get an
131+
// a custom iterator() function. Otherwise we get an
132132
// IndexingGenerator. <rdar://problem/21539115>
133-
func generate() -> Iterator
133+
func iterator() -> Iterator
134134

135135
// FIXME: should be constrained to CollectionType
136136
// (<rdar://problem/20715009> Implement recursive protocol
@@ -195,11 +195,11 @@ public protocol CollectionType : Indexable, SequenceType {
195195
var first: Iterator.Element? { get }
196196
}
197197

198-
/// Supply the default `generate()` method for `CollectionType` models
198+
/// Supply the default `iterator()` method for `CollectionType` models
199199
/// that accept the default associated `Iterator`,
200200
/// `IndexingGenerator<Self>`.
201201
extension CollectionType where Iterator == IndexingGenerator<Self> {
202-
public func generate() -> IndexingGenerator<Self> {
202+
public func iterator() -> IndexingGenerator<Self> {
203203
return IndexingGenerator(self)
204204
}
205205
}
@@ -739,7 +739,7 @@ public struct PermutationGenerator<
739739
/// - Requires: `elements[i]` is valid for every `i` in `indices`.
740740
public init(elements: C, indices: Indices) {
741741
self.seq = elements
742-
self.indices = indices.generate()
742+
self.indices = indices.iterator()
743743
}
744744
}
745745

0 commit comments

Comments
 (0)