[stdlib] Add post-nil guarantee for IteratorProtocol.next() to always return nil

This commit is contained in:
Patrick Pijnappel
2016-03-16 22:06:07 +11:00
parent 149fd438a1
commit 020841d4ba
14 changed files with 40 additions and 57 deletions

View File

@@ -84,10 +84,8 @@ public struct EnumeratedIterator<
/// The type of element returned by `next()`.
public typealias Element = (offset: Int, element: Base.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`.
/// Advance to the next element and return it, or `nil` if no next element
/// exists. Once `nil` has been returned, all subsequent calls return `nil`.
public mutating func next() -> Element? {
guard let b = _base.next() else { return nil }
defer { _count += 1 }