Skip to content

Commit

Permalink
Rename SequenceType.generate() to SequenceType.iterator()
Browse files Browse the repository at this point in the history
  • Loading branch information
gribozavr authored and Max Moiseev committed Dec 10, 2015
1 parent 2cf1721 commit 1c00478
Show file tree
Hide file tree
Showing 93 changed files with 392 additions and 392 deletions.
14 changes: 7 additions & 7 deletions docs/SequencesAndCollections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ represented by the `SequenceType` protocol::

protocol SequenceType {
typealias Iterator : IteratorProtocol
func generate() -> Iterator
func iterator() -> Iterator
}

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/archive/LangRef.html
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ <h4 id="protocol-member-typealias">'typealias' protocol elements (associated typ
<pre class="example">
protocol SequenceType {
typename Iterator : IteratorProtocol
func generate() -> Iterator
func iterator() -> Iterator
}
</pre>

Expand Down
4 changes: 2 additions & 2 deletions docs/proposals/DeclarationTypeChecker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ We can address this problem by restricting the language to disallow extensions v

protocol SequenceType {
typealias Element
mutating func generate() -> Element?
mutating func iterator() -> Element?
}

struct IntRangeGenerator : SequenceType {
var current: Int
let limit: Int

// infers SequenceType's Element == Int
mutating func generate() -> Int? {
mutating func iterator() -> Int? {
if current == limit { return nil }
return current++
}
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ IDENTIFIER(error)
IDENTIFIER(forKeyedSubscript)
IDENTIFIER(Foundation)
IDENTIFIER(fromRaw)
IDENTIFIER(generate)
IDENTIFIER(hashValue)
IDENTIFIER(init)
IDENTIFIER(iterator)
IDENTIFIER(Iterator)
IDENTIFIER(load)
IDENTIFIER(next)
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
S->setSequence(sequence);
}

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

Expr *getIterator
= TC.callWitness(sequence, DC, sequenceProto, conformance,
TC.Context.Id_generate,
TC.Context.Id_iterator,
{}, diag::sequence_protocol_broken);
if (!getIterator) return nullptr;

Expand Down
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/CheckCollectionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ extension TestSuite {
testNamePrefix += String(Collection.Type)

//===----------------------------------------------------------------------===//
// generate()
// iterator()
//===----------------------------------------------------------------------===//

self.test("\(testNamePrefix).generate()/semantics") {
self.test("\(testNamePrefix).iterator()/semantics") {
for test in subscriptRangeTests {
let c = makeWrappedCollection(test.collection)
for _ in 0..<3 {
Expand Down
8 changes: 4 additions & 4 deletions stdlib/private/StdlibUnittest/LoggingWrappers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ public struct LoggingRangeReplaceableCollection<
return try base.filter(includeElement)
}

public func generate() -> Base.Iterator {
return base.generate()
public func iterator() -> Base.Iterator {
return base.iterator()
}
}

Expand Down Expand Up @@ -447,9 +447,9 @@ public struct Logging${Kind}<Base: ${Kind}Type> : ${Kind}Type, LoggingType {
}
% end

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

public func underestimateCount() -> Int {
Expand Down
24 changes: 12 additions & 12 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ public func checkSequence<
) {
let expectedCount: Int = numericCast(expected.count)
checkIterator(
expected, sequence.generate(), ${trace},
expected, sequence.iterator(), ${trace},
resiliencyChecks: resiliencyChecks,
sameValue: sameValue)

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

/// State that is created every time a fresh iterator is created with
/// `MinimalSequence.generate()`.
/// `MinimalSequence.iterator()`.
internal class _MinimalIteratorPrivateState<T> {
internal init() {}

Expand Down Expand Up @@ -2583,8 +2583,8 @@ extension StrictSequenceType {
}

extension StrictSequenceType where Iterator : _MinimalIteratorProtocol {
public func generate() -> MinimalIterator<Element> {
return base.generate()
public func iterator() -> MinimalIterator<Element> {
return base.iterator()
}
}

Expand Down Expand Up @@ -2615,7 +2615,7 @@ public struct MinimalSequence<T> : SequenceType, CustomDebugStringConvertible {
}
}

public func generate() -> MinimalIterator<T> {
public func iterator() -> MinimalIterator<T> {
return MinimalIterator(_sharedState)
}

Expand Down Expand Up @@ -3332,8 +3332,8 @@ extension ${Protocol} {
}

extension ${Protocol} where Iterator : _MinimalIteratorProtocol {
public func generate() -> MinimalIterator<Element> {
return base.generate()
public func iterator() -> MinimalIterator<Element> {
return base.iterator()
}
}

Expand Down Expand Up @@ -3386,7 +3386,7 @@ public struct ${Self}<T> : ${'MutableCollectionType' if mutable else 'Collection
}
}

public func generate() -> MinimalIterator<T> {
public func iterator() -> MinimalIterator<T> {
return MinimalIterator(_elements)
}

Expand Down Expand Up @@ -3461,8 +3461,8 @@ extension ${Protocol} {
}

extension ${Protocol} where Iterator : _MinimalIteratorProtocol {
public func generate() -> MinimalIterator<Element> {
return base.generate()
public func iterator() -> MinimalIterator<Element> {
return base.iterator()
}
}

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

public func generate() -> MinimalIterator<T> {
public func iterator() -> MinimalIterator<T> {
return MinimalIterator(elements)
}

Expand Down Expand Up @@ -3917,7 +3917,7 @@ public struct Defaulted${traversal}RangeReplaceableSlice<Element>
base: Base(elements: elements))
}

public func generate() -> MinimalIterator<Element> {
public func iterator() -> MinimalIterator<Element> {
return MinimalIterator(Array(self))
}

Expand Down
12 changes: 6 additions & 6 deletions stdlib/public/SDK/Foundation/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ extension NSArray : SequenceType {
/// Return an *iterator* over the elements of this *sequence*.
///
/// - Complexity: O(1).
final public func generate() -> NSFastEnumerationIterator {
final public func iterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}
Expand Down Expand Up @@ -769,7 +769,7 @@ extension NSSet : SequenceType {
/// Return an *iterator* over the elements of this *sequence*.
///
/// - Complexity: O(1).
public func generate() -> NSFastEnumerationIterator {
public func iterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}
Expand All @@ -778,7 +778,7 @@ extension NSOrderedSet : SequenceType {
/// Return an *iterator* over the elements of this *sequence*.
///
/// - Complexity: O(1).
public func generate() -> NSFastEnumerationIterator {
public func iterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}
Expand Down Expand Up @@ -816,7 +816,7 @@ extension NSIndexSet : SequenceType {
/// Return an *iterator* over the elements of this *sequence*.
///
/// - Complexity: O(1).
public func generate() -> NSIndexSetIterator {
public func iterator() -> NSIndexSetIterator {
return NSIndexSetIterator(set: self)
}
}
Expand Down Expand Up @@ -942,7 +942,7 @@ extension NSDictionary : SequenceType {
/// Return an *iterator* over the elements of this *sequence*.
///
/// - Complexity: O(1).
public func generate() -> Iterator {
public func iterator() -> Iterator {
return Iterator(self)
}
}
Expand All @@ -951,7 +951,7 @@ extension NSEnumerator : SequenceType {
/// Return an *iterator* over the *enumerator*.
///
/// - Complexity: O(1).
public func generate() -> NSFastEnumerationIterator {
public func iterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}
Expand Down
12 changes: 6 additions & 6 deletions stdlib/public/core/Algorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public func max<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
/// starting at zero, along with the elements of the underlying
/// `Base`:
///
/// var g = EnumeratedIterator(["foo", "bar"].generate())
/// g.next() // (0, "foo")
/// g.next() // (1, "bar")
/// g.next() // nil
/// var iterator = ["foo", "bar"].enumerate()
/// iterator.next() // (0, "foo")
/// iterator.next() // (1, "bar")
/// iterator.next() // nil
///
/// - Note: Idiomatic usage is to call `enumerate` instead of
/// constructing an `EnumeratedIterator` directly.
Expand Down Expand Up @@ -123,8 +123,8 @@ public struct EnumeratedSequence<Base : SequenceType> : SequenceType {
/// Returns an *iterator* over the elements of this *sequence*.
///
/// - Complexity: O(1).
public func generate() -> EnumeratedIterator<Base.Iterator> {
return EnumeratedIterator(_base: _base.generate())
public func iterator() -> EnumeratedIterator<Base.Iterator> {
return EnumeratedIterator(_base: _base.iterator())
}
}

6 changes: 3 additions & 3 deletions stdlib/public/core/Arrays.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ internal func _arrayAppendSequence<
>(
inout buffer: Buffer, _ newItems: S
) {
var stream = newItems.generate()
var stream = newItems.iterator()
var nextItem = stream.next()

if nextItem == nil {
Expand Down Expand Up @@ -1262,8 +1262,8 @@ public func == <Element : Equatable>(
return true
}

var streamLHS = lhs.generate()
var streamRHS = rhs.generate()
var streamLHS = lhs.iterator()
var streamRHS = rhs.iterator()

var nextLHS = streamLHS.next()
while nextLHS != nil {
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/Character.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public struct Character :
internal var _data: UInt64
}

internal func generate() -> Iterator {
internal func iterator() -> Iterator {
return Iterator(data)
}

Expand All @@ -199,7 +199,7 @@ public struct Character :
struct _SmallUTF16 : CollectionType {
init(_ u8: UInt64) {
let count = UTF16.measure(
UTF8.self, input: _SmallUTF8(u8).generate(),
UTF8.self, input: _SmallUTF8(u8).iterator(),
repairIllFormedSequences: true)!.0
_sanityCheck(count <= 4, "Character with more than 4 UTF-16 code units")
self.count = UInt16(count)
Expand All @@ -209,7 +209,7 @@ public struct Character :
u16 = u16 | UInt64($0)
}
transcode(
UTF8.self, UTF16.self, _SmallUTF8(u8).generate(), output,
UTF8.self, UTF16.self, _SmallUTF8(u8).iterator(), output,
stopOnError: false)
self.data = u16
}
Expand Down
14 changes: 7 additions & 7 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public protocol MutableIndexable {
/// An *iterator* for an arbitrary *collection*. Provided `C`
/// conforms to the other requirements of `Indexable`,
/// `IndexingGenerator<C>` can be used as the result of `C`'s
/// `generate()` method. For example:
/// `iterator()` method. For example:
///
/// struct MyCollection : CollectionType {
/// struct Index : ForwardIndexType { /* implementation hidden */ }
/// subscript(i: Index) -> MyElement { /* implementation hidden */ }
/// func generate() -> IndexingGenerator<MyCollection> { // <===
/// func iterator() -> IndexingGenerator<MyCollection> { // <===
/// return IndexingGenerator(self)
/// }
/// }
Expand Down Expand Up @@ -128,9 +128,9 @@ public protocol CollectionType : Indexable, SequenceType {
typealias Iterator : IteratorProtocol = IndexingGenerator<Self>

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

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

/// Supply the default `generate()` method for `CollectionType` models
/// Supply the default `iterator()` method for `CollectionType` models
/// that accept the default associated `Iterator`,
/// `IndexingGenerator<Self>`.
extension CollectionType where Iterator == IndexingGenerator<Self> {
public func generate() -> IndexingGenerator<Self> {
public func iterator() -> IndexingGenerator<Self> {
return IndexingGenerator(self)
}
}
Expand Down Expand Up @@ -739,7 +739,7 @@ public struct PermutationGenerator<
/// - Requires: `elements[i]` is valid for every `i` in `indices`.
public init(elements: C, indices: Indices) {
self.seq = elements
self.indices = indices.generate()
self.indices = indices.iterator()
}
}

Expand Down
Loading

0 comments on commit 1c00478

Please sign in to comment.