Cursor

A type that supplies the values of some external resource, one at a time.

Cursor.swift:304
protocol Cursor<Element> : AnyObject
Browse conforming types

Overview

To iterate over the elements of a cursor, use a while loop:

while let element = try cursor.next() {
    print(element)
}

Relationship with standard Sequence and IteratorProtocol

Cursors share traits with lazy sequences and iterators from the Swift standard library. Differences are:

  • Cursor types are classes, and have a lifetime.

  • Cursor iteration may throw errors.

  • A cursor can not be repeated.

The protocol comes with default implementations for many operations similar to those defined by Swift’s Sequence protocol: contains, dropFirst, dropLast, drop(while:), enumerated, filter, first, flatMap, forEach, joined, joined(separator:), max, max(by:), min, min(by:), map, prefix, prefix(while:), reduce, reduce(into:), suffix.

Supporting Types