[stdlib] Propagate GeneratorType docs to models

Swift SVN r22208
This commit is contained in:
Dave Abrahams
2014-09-23 09:47:26 +00:00
parent d4de1bf5e9
commit 76f9313088
15 changed files with 77 additions and 7 deletions

View File

@@ -215,6 +215,7 @@ public func startsWith<
public struct EnumerateGenerator< public struct EnumerateGenerator<
Base: GeneratorType Base: GeneratorType
> : GeneratorType, SequenceType { > : GeneratorType, SequenceType {
/// The type of element returned by `next()`.
public typealias Element = (index: Int, element: Base.Element) public typealias Element = (index: Int, element: Base.Element)
var base: Base var base: Base
var count: Int var count: Int
@@ -225,8 +226,10 @@ public struct EnumerateGenerator<
count = 0 count = 0
} }
/// If all elements are exhausted, return `nil`. Otherwise, advance /// Advance to the next element and return it, or `nil` if no next
/// to the next element and return it. /// element exists.
///
/// Requires: no preceding call to `self.next()` has returned `nil`.
public mutating func next() -> Element? { public mutating func next() -> Element? {
var b = base.next() var b = base.next()
if b == nil { return .None } if b == nil { return .None }

View File

@@ -175,8 +175,10 @@ public struct IndexingGenerator<
return self return self
} }
/// Return the next element of the underlying collection, or `nil` /// Advance to the next element and return it, or `nil` if no next
/// if no next element exists. /// element exists.
///
/// Requires: no preceding call to `self.next()` has returned `nil`.
public mutating func next() -> C._Element? { public mutating func next() -> C._Element? {
return _position == _elements.endIndex return _position == _elements.endIndex
? .None : .Some(_elements[_position++]) ? .None : .Some(_elements[_position++])
@@ -206,8 +208,13 @@ public struct PermutationGenerator<
var seq : C var seq : C
var indices : Indices.Generator var indices : Indices.Generator
/// The type of element returned by `next()`.
public typealias Element = C.Generator.Element public typealias Element = C.Generator.Element
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: no preceding call to `self.next()` has returned `nil`.
public mutating func next() -> Element? { public mutating func next() -> Element? {
var result = indices.next() var result = indices.next()
return result != nil ? seq[result!] : .None return result != nil ? seq[result!] : .None

View File

@@ -20,6 +20,12 @@ public struct GeneratorOfOne<T> : GeneratorType, SequenceType {
return self return self
} }
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: `next()` has not been applied to a copy of `self`
/// since the copy was made, and no preceding call to `self.next()`
/// has returned `nil`.
public mutating func next() -> T? { public mutating func next() -> T? {
let result = elements let result = elements
elements = .None elements = .None

View File

@@ -39,7 +39,7 @@ public protocol BooleanType {
/// Also, the generators must be obtained by distinct calls to the /// Also, the generators must be obtained by distinct calls to the
/// *sequence's* `generate()` method, rather than by copying. /// *sequence's* `generate()` method, rather than by copying.
public protocol GeneratorType { public protocol GeneratorType {
/// The type of element to be bound to the loop variable. /// The type of element generated by `self`.
typealias Element typealias Element
/// Advance to the next element and return it, or `nil` if no next /// Advance to the next element and return it, or `nil` if no next
@@ -170,6 +170,12 @@ public struct GeneratorSequence<
_base = base _base = base
} }
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: `next()` has not been applied to a copy of `self`
/// since the copy was made, and no preceding call to `self.next()`
/// has returned `nil`.
public mutating func next() -> G.Element? { public mutating func next() -> G.Element? {
return _base.next() return _base.next()
} }

View File

@@ -23,8 +23,12 @@ struct _ConcatenateSequenceGenerator<
self._outer = outer self._outer = outer
} }
/// Return the next element in the sequence, or `nil`` if none exists, /// Advance to the next element and return it, or `nil` if no next
/// in either case advancing the generator. /// element exists.
///
/// Requires: `next()` has not been applied to a copy of `self`
/// since the copy was made, and no preceding call to `self.next()`
/// has returned `nil`.
mutating func next() -> Outer.Element.Generator.Element? { mutating func next() -> Outer.Element.Generator.Element? {
do { do {
if _fastPath(_inner != nil) { if _fastPath(_inner != nil) {

View File

@@ -1883,6 +1883,10 @@ public struct DictionaryGenerator<Key : Hashable, Value> : GeneratorType {
} }
} }
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: no preceding call to `self.next()` has returned `nil`.
public mutating func next() -> (Key, Value)? { public mutating func next() -> (Key, Value)? {
if _fastPath(_guaranteedNative) { if _fastPath(_guaranteedNative) {
return _nativeNext() return _nativeNext()

View File

@@ -22,6 +22,7 @@ public struct EmptyGenerator<T> : GeneratorType, SequenceType {
return self return self
} }
/// Return `nil`, indicating that there are no more elements.
public mutating func next() -> T? { public mutating func next() -> T? {
return nil return nil
} }

View File

@@ -26,6 +26,12 @@ public struct GeneratorOf<T> : GeneratorType, SequenceType {
self._next = { self_.next() } self._next = { self_.next() }
} }
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: `next()` has not been applied to a copy of `self`
/// since the copy was made, and no preceding call to `self.next()`
/// has returned `nil`.
public mutating func next() -> T? { public mutating func next() -> T? {
return _next() return _next()
} }

View File

@@ -15,6 +15,12 @@
public struct FilterGenerator< public struct FilterGenerator<
Base: GeneratorType Base: GeneratorType
> : GeneratorType, SequenceType { > : GeneratorType, SequenceType {
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: `next()` has not been applied to a copy of `self`
/// since the copy was made, and no preceding call to `self.next()`
/// has returned `nil`.
public mutating func next() -> Base.Element? { public mutating func next() -> Base.Element? {
var n: Base.Element? var n: Base.Element?
for/*ever*/;; { for/*ever*/;; {

View File

@@ -16,6 +16,12 @@
public struct MapSequenceGenerator< public struct MapSequenceGenerator<
Base: GeneratorType, T Base: GeneratorType, T
>: GeneratorType, SequenceType { >: GeneratorType, SequenceType {
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: `next()` has not been applied to a copy of `self`
/// since the copy was made, and no preceding call to `self.next()`
/// has returned `nil`.
public mutating func next() -> T? { public mutating func next() -> T? {
let x = _base.next() let x = _base.next()
if x != nil { if x != nil {

View File

@@ -13,6 +13,7 @@
public struct RangeGenerator< public struct RangeGenerator<
T: ForwardIndexType T: ForwardIndexType
> : GeneratorType, SequenceType { > : GeneratorType, SequenceType {
/// The type of element returned by `next()`.
public typealias Element = T public typealias Element = T
@transparent public @transparent public
@@ -21,6 +22,8 @@ public struct RangeGenerator<
self.endIndex = bounds.endIndex self.endIndex = bounds.endIndex
} }
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
public mutating func next() -> Element? { public mutating func next() -> Element? {
if startIndex == endIndex { if startIndex == endIndex {
return .None return .None

View File

@@ -85,6 +85,8 @@ public struct StrideToGenerator<T: Strideable> : GeneratorType {
let end: T let end: T
let stride: T.Stride let stride: T.Stride
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
public mutating func next() -> T? { public mutating func next() -> T? {
if stride > 0 ? current >= end : current <= end { if stride > 0 ? current >= end : current <= end {
return nil return nil
@@ -130,6 +132,8 @@ public struct StrideThroughGenerator<T: Strideable> : GeneratorType {
let stride: T.Stride let stride: T.Stride
var done: Bool = false var done: Bool = false
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
public mutating func next() -> T? { public mutating func next() -> T? {
if done { if done {
return nil return nil

View File

@@ -125,6 +125,11 @@ extension String {
self._base = _base self._base = _base
} }
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: no preceding call to `self.next()` has returned
/// `nil`.
public mutating func next() -> UnicodeScalar? { public mutating func next() -> UnicodeScalar? {
switch _decoder.decode(&self._base) { switch _decoder.decode(&self._base) {
case .Result(let us): case .Result(let us):

View File

@@ -13,6 +13,8 @@
/// A generator for the elements in the buffer referenced by /// A generator for the elements in the buffer referenced by
/// `UnsafeBufferPointer` or `UnsafeMutableBufferPointer` /// `UnsafeBufferPointer` or `UnsafeMutableBufferPointer`
public struct UnsafeBufferPointerGenerator<T>: GeneratorType, SequenceType { public struct UnsafeBufferPointerGenerator<T>: GeneratorType, SequenceType {
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
public mutating func next() -> T? { public mutating func next() -> T? {
return position == end ? nil : (position++).memory return position == end ? nil : (position++).memory
} }

View File

@@ -13,12 +13,19 @@
public struct ZipGenerator2< public struct ZipGenerator2<
E0 : GeneratorType, E1 : GeneratorType E0 : GeneratorType, E1 : GeneratorType
> : GeneratorType { > : GeneratorType {
/// The type of element returned by `next()`.
public typealias Element = (E0.Element,E1.Element) public typealias Element = (E0.Element,E1.Element)
public init(_ e0: E0, _ e1: E1) { public init(_ e0: E0, _ e1: E1) {
baseStreams = (e0,e1) baseStreams = (e0,e1)
} }
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// Requires: `next()` has not been applied to a copy of `self`
/// since the copy was made, and no preceding call to `self.next()`
/// has returned `nil`.
public mutating func next() -> Element? { public mutating func next() -> Element? {
var e0 = baseStreams.0.next() var e0 = baseStreams.0.next()
if e0 == nil { return .None } if e0 == nil { return .None }