diff --git a/CHANGELOG.md b/CHANGELOG.md index 1470197e4..e153e9f9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,13 @@ Release Notes ### Breaking Changes -- `Request` and `TypedRequest` protocols have been merged into `FetchRequest`. +- `Request` and `TypedRequest` protocols have been merged into `FetchRequest` ([311](https://github.com/groue/GRDB.swift/pull/311)) +- The `IteratorCursor` type has been removed. Use `AnyCursor` instead. + ### API diff -FetchRequest +**FetchRequest** ```diff +protocol FetchRequest { @@ -99,6 +101,17 @@ FetchRequest +extension QueryInterfaceRequest : FetchRequest { } ``` +**Cursor** + +```diff + final class AnyCursor : Cursor { ++ convenience init(iterator: I) where I.Element == Element ++ convenience init(_ s: S) where S.Element == Element + } +-final class IteratorCursor : Cursor { } +``` + + ## 2.9.0 Released February 25, 2018 • [diff](https://github.com/groue/GRDB.swift/compare/v2.8.0...v2.9.0) diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index 5b5b41f10..f077d9133 100755 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -76,8 +76,6 @@ 5623931C1DECC02000A6B01F /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393171DECC02000A6B01F /* RowFetchTests.swift */; }; 562393301DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; 562393341DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; - 562393451DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; - 562393491DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; 5623934E1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; 562393521DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; 562393571DEE013C00A6B01F /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393561DEE013C00A6B01F /* FilterCursorTests.swift */; }; @@ -775,7 +773,6 @@ 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; 562393171DECC02000A6B01F /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; - 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IteratorCursorTests.swift; sourceTree = ""; }; 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; 562393561DEE013C00A6B01F /* FilterCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterCursorTests.swift; sourceTree = ""; }; 5623935F1DEE06D300A6B01F /* CursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CursorTests.swift; sourceTree = ""; }; @@ -1651,7 +1648,6 @@ 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */, 562393561DEE013C00A6B01F /* FilterCursorTests.swift */, 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */, - 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */, 562393711DEE104400A6B01F /* MapCursorTests.swift */, 56CC9250201E093E00CB597E /* PrefixCursorTests.swift */, 56CC9242201E034D00CB597E /* PrefixWhileCursorTests.swift */, @@ -2414,7 +2410,6 @@ 56A2384E1B9C74A90082EB20 /* DatabaseMigratorTests.swift in Sources */, 56CC9244201E034D00CB597E /* PrefixWhileCursorTests.swift in Sources */, 5657AB4A1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */, - 562393491DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, 569531351C919DF200CF1A2B /* DatabasePoolCollationTests.swift in Sources */, 56A2385A1B9C74A90082EB20 /* RecordPrimaryKeySingleTests.swift in Sources */, 56EE573E1BB317B7007A6A95 /* StatementColumnConvertibleTests.swift in Sources */, @@ -2656,7 +2651,6 @@ 56E5D8041B4D424400430942 /* GRDBTestCase.swift in Sources */, 567DAF351EAB789800FC0928 /* DatabaseLogErrorTests.swift in Sources */, 56D496681D813086008276D7 /* RowConvertible+QueryInterfaceRequestTests.swift in Sources */, - 562393451DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, 5623934E1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */, 568068311EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */, 56D496B41D8133F8008276D7 /* DatabaseTests.swift in Sources */, diff --git a/GRDB/Core/Cursor.swift b/GRDB/Core/Cursor.swift index 7afea0a74..8de34aebe 100644 --- a/GRDB/Core/Cursor.swift +++ b/GRDB/Core/Cursor.swift @@ -28,8 +28,8 @@ extension Sequence { /// Returns a cursor over the concatenated results of mapping transform /// over self. - public func flatMap(_ transform: @escaping (Iterator.Element) throws -> SegmentOfResult) -> FlattenCursor, SegmentOfResult>> { - return IteratorCursor(self).flatMap(transform) + public func flatMap(_ transform: @escaping (Iterator.Element) throws -> SegmentOfResult) -> FlattenCursor, SegmentOfResult>> { + return AnyCursor(self).flatMap(transform) } } @@ -168,7 +168,7 @@ extension Cursor { /// If the number of elements to drop exceeds the number of elements in /// the cursor, the result is an empty cursor. /// - /// let numbers = IteratorCursor([1, 2, 3, 4, 5]) + /// let numbers = AnyCursor([1, 2, 3, 4, 5]) /// try print(numbers.dropFirst(2)) /// // Prints "[3, 4, 5]" /// try print(numbers.dropFirst(10)) @@ -186,7 +186,7 @@ extension Cursor { /// /// The following example drops the first element from a cursor of integers. /// - /// let numbers = IteratorCursor([1, 2, 3, 4, 5]) + /// let numbers = AnyCursor([1, 2, 3, 4, 5]) /// try print(numbers.dropFirst()) /// // Prints "[2, 3, 4, 5]" /// @@ -203,7 +203,7 @@ extension Cursor { /// The cursor must be finite. If the number of elements to drop exceeds /// the number of elements in the cursor, the result is an empty array. /// - /// let numbers = IteratorCursor([1, 2, 3, 4, 5]) + /// let numbers = AnyCursor([1, 2, 3, 4, 5]) /// try print(numbers.dropLast(2)) /// // Prints "[1, 2, 3]" /// try print(numbers.dropLast(10)) @@ -236,7 +236,7 @@ extension Cursor { /// /// The following example drops the last element from a cursor of integers. /// - /// let numbers = IteratorCursor([1, 2, 3, 4, 5]) + /// let numbers = AnyCursor([1, 2, 3, 4, 5]) /// try print(numbers.dropLast()) /// // Prints "[1, 2, 3, 4]" /// @@ -249,8 +249,8 @@ extension Cursor { /// Returns a cursor over the concatenated results of mapping transform /// over self. - public func flatMap(_ transform: @escaping (Element) throws -> SegmentOfResult) -> FlattenCursor>> { - return flatMap { try IteratorCursor(transform($0)) } + public func flatMap(_ transform: @escaping (Element) throws -> SegmentOfResult) -> FlattenCursor>> { + return flatMap { try AnyCursor(transform($0)) } } /// Returns a cursor over the concatenated results of mapping transform @@ -318,7 +318,7 @@ extension Cursor { /// If the maximum length exceeds the number of elements in the cursor, /// the result contains all the elements in the cursor. /// - /// let numbers = IteratorCursor([1, 2, 3, 4, 5]) + /// let numbers = AnyCursor([1, 2, 3, 4, 5]) /// try print(numbers.prefix(2)) /// // Prints "[1, 2]" /// try print(numbers.prefix(10)) @@ -378,7 +378,7 @@ extension Cursor { /// elements in the cursor, the result contains all the elements in the /// cursor. /// - /// let numbers = IteratorCursor([1, 2, 3, 4, 5]) + /// let numbers = AnyCursor([1, 2, 3, 4, 5]) /// try print(numbers.suffix(2)) /// // Prints "[4, 5]" /// try print(numbers.suffix(10)) @@ -472,7 +472,7 @@ extension Cursor where Element: Cursor { extension Cursor where Element: Sequence { /// Returns the elements of this cursor of sequences, concatenated. - public func joined() -> FlattenCursor>> { + public func joined() -> FlattenCursor>> { return flatMap { $0 } } } @@ -509,7 +509,7 @@ extension Cursor where Element: StringProtocol { /// This cursor forwards its next() method to an arbitrary underlying cursor /// having the same Element type, hiding the specifics of the underlying /// cursor. -public class AnyCursor : Cursor { +public final class AnyCursor : Cursor { private let element: () throws -> Element? /// Creates a cursor that wraps a base cursor but whose type depends only on @@ -518,6 +518,19 @@ public class AnyCursor : Cursor { element = base.next } + /// Creates a cursor that wraps a base iterator but whose type depends only + /// on the base iterator’s element type + public convenience init(iterator: I) where I.Element == Element { + var iterator = iterator + self.init { iterator.next() } + } + + /// Creates a cursor that wraps a base sequence but whose type depends only + /// on the base sequence’s element type + public convenience init(_ s: S) where S.Element == Element { + self.init(iterator: s.makeIterator()) + } + /// Creates a cursor that wraps the given closure in its next() method public init(_ body: @escaping () throws -> Element?) { element = body @@ -749,25 +762,3 @@ public final class PrefixWhileCursor : Cursor { return nil } } - -/// A Cursor whose elements are those of a sequence iterator. -public final class IteratorCursor : Cursor { - private var base: Base - - /// Creates a cursor from a sequence iterator. - public init(_ base: Base) { - self.base = base - } - - /// Creates a cursor from a sequence. - public init(_ s: S) where S.Iterator == Base { - self.base = s.makeIterator() - } - - /// Advances to the next element and returns it, or nil if no next - /// element exists. - /// :nodoc: - public func next() -> Base.Element? { - return base.next() - } -} diff --git a/GRDBCipher.xcodeproj/project.pbxproj b/GRDBCipher.xcodeproj/project.pbxproj index 6988346fe..bb104a6f2 100755 --- a/GRDBCipher.xcodeproj/project.pbxproj +++ b/GRDBCipher.xcodeproj/project.pbxproj @@ -141,10 +141,6 @@ 562393321DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; 562393351DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; 562393361DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; - 562393461DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; - 562393471DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; - 5623934A1DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; - 5623934B1DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; 5623934F1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; 562393501DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; 562393531DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; @@ -857,7 +853,6 @@ 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; 562393171DECC02000A6B01F /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; - 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IteratorCursorTests.swift; sourceTree = ""; }; 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; 562393561DEE013C00A6B01F /* FilterCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterCursorTests.swift; sourceTree = ""; }; 5623935F1DEE06D300A6B01F /* CursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CursorTests.swift; sourceTree = ""; }; @@ -1630,7 +1625,6 @@ 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */, 562393561DEE013C00A6B01F /* FilterCursorTests.swift */, 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */, - 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */, 562393711DEE104400A6B01F /* MapCursorTests.swift */, 56CC9256201E094E00CB597E /* PrefixCursorTests.swift */, 56CC923D201E034200CB597E /* PrefixWhileCursorTests.swift */, @@ -2137,7 +2131,6 @@ 566AD8C71D531BEA002EC1A8 /* TableDefinitionTests.swift in Sources */, 560FC5781CB00B880014AA8E /* RowFromStatementTests.swift in Sources */, 560FC5791CB00B880014AA8E /* RecordPrimaryKeyMultipleTests.swift in Sources */, - 562393461DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, 56CC9257201E094F00CB597E /* PrefixCursorTests.swift in Sources */, 5698AC971DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, 5657AB4F1D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */, @@ -2287,7 +2280,6 @@ 567156371CB16729007DC145 /* RecordPrimaryKeyMultipleTests.swift in Sources */, 5657AB401D108BA9006283EF /* FoundationNSDataTests.swift in Sources */, 56CC9258201E094F00CB597E /* PrefixCursorTests.swift in Sources */, - 562393471DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, 5698AC981DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, 56CC9237201E009800CB597E /* DropWhileCursorTests.swift in Sources */, 56D507601F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */, @@ -2597,7 +2589,6 @@ 56176C741EACCCCA000F3F2B /* FTS5TableBuilderTests.swift in Sources */, 5657AB3B1D108BA9006283EF /* FoundationDataTests.swift in Sources */, 5698AC081D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, - 5623934A1DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, 56AFCA661CB1AA9900F48B96 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, 561667061D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */, 565EFAF31D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, @@ -2745,7 +2736,6 @@ 56176C7A1EACCCCB000F3F2B /* FTS5TableBuilderTests.swift in Sources */, 561667071D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */, 5698AC091D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, - 5623934B1DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, 56AFCABD1CB1ABC800F48B96 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 56AFCABE1CB1ABC800F48B96 /* DatabaseErrorTests.swift in Sources */, 56AFCABF1CB1ABC800F48B96 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, diff --git a/GRDBCustom.xcodeproj/project.pbxproj b/GRDBCustom.xcodeproj/project.pbxproj index d02cf9602..d287e61dc 100755 --- a/GRDBCustom.xcodeproj/project.pbxproj +++ b/GRDBCustom.xcodeproj/project.pbxproj @@ -23,8 +23,6 @@ 5623931F1DECC02000A6B01F /* RowFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393171DECC02000A6B01F /* RowFetchTests.swift */; }; 562393331DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; 562393371DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */; }; - 562393481DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; - 5623934C1DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */; }; 562393511DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; 562393551DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */; }; 5623935A1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393561DEE013C00A6B01F /* FilterCursorTests.swift */; }; @@ -556,7 +554,6 @@ 561667001D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDecimalNumberTests.swift; sourceTree = ""; }; 562393171DECC02000A6B01F /* RowFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFetchTests.swift; sourceTree = ""; }; 5623932F1DEDFC5700A6B01F /* AnyCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCursorTests.swift; sourceTree = ""; }; - 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IteratorCursorTests.swift; sourceTree = ""; }; 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumeratedCursorTests.swift; sourceTree = ""; }; 562393561DEE013C00A6B01F /* FilterCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterCursorTests.swift; sourceTree = ""; }; 5623935F1DEE06D300A6B01F /* CursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CursorTests.swift; sourceTree = ""; }; @@ -1302,7 +1299,6 @@ 5623934D1DEDFEFB00A6B01F /* EnumeratedCursorTests.swift */, 562393561DEE013C00A6B01F /* FilterCursorTests.swift */, 562393681DEE0CD200A6B01F /* FlattenCursorTests.swift */, - 562393441DEDFE4500A6B01F /* IteratorCursorTests.swift */, 562393711DEE104400A6B01F /* MapCursorTests.swift */, 56CC9253201E094600CB597E /* PrefixCursorTests.swift */, 56CC923A201E033400CB597E /* PrefixWhileCursorTests.swift */, @@ -1799,7 +1795,6 @@ F3BA80B91CFB2FD1003DC1BA /* DatabasePoolBackupTests.swift in Sources */, F3BA811E1CFB3063003DC1BA /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */, 562EA8361F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */, - 5623934C1DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, F3BA80DD1CFB300E003DC1BA /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 5644488A1EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */, F3BA80521CFB2B59003DC1BA /* DatabaseQueueSchemaCacheTests.swift in Sources */, @@ -2085,7 +2080,6 @@ F3BA80FF1CFB3025003DC1BA /* TransactionObserverSavepointsTests.swift in Sources */, 5698AC4C1DA2D48A0056AF8C /* FTS3RecordTests.swift in Sources */, F3BA80EF1CFB3017003DC1BA /* RowFromStatementTests.swift in Sources */, - 562393481DEDFE4500A6B01F /* IteratorCursorTests.swift in Sources */, 5657AB511D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */, 56CC9254201E094600CB597E /* PrefixCursorTests.swift in Sources */, 562393331DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */, diff --git a/TODO.md b/TODO.md index ae14caca0..9d6bde776 100644 --- a/TODO.md +++ b/TODO.md @@ -33,8 +33,7 @@ GRDB 3.0 - [ ] Rename Request to FetchRequest, because Request is a bad name: https://github.com/swift-server/http/pull/7#issuecomment-308448528 - [ ] Rename RowConvertible, TableMapping, MutablePersistable and Persistable so that their names contain Record: FetchableRecord, TableRecord, MutablePersistableRecord, PersistableRecord? - [ ] Not sure: Consider introducing RowDecodable and RowEncodable on top of FetchableRecord and MutablePersistableRecord. This would allow keeping fetching and persistence methods private in some files. -- [ ] Drop IteratorCursor, use AnyCursor instead -<<<<<<< HEAD +- [X] Drop IteratorCursor, use AnyCursor instead - [X] Rename TypedRequest to FetchRequest, drop Request - [ ] Rename columnCount -> numberOfColumns - [ ] Try to remove double Persistable/MutablePersistable protocols: Would non-mutating Record methods help? diff --git a/Tests/GRDBTests/AnyCursorTests.swift b/Tests/GRDBTests/AnyCursorTests.swift index 611bf94c4..7a8a86675 100644 --- a/Tests/GRDBTests/AnyCursorTests.swift +++ b/Tests/GRDBTests/AnyCursorTests.swift @@ -42,9 +42,9 @@ class AnyCursorTests: GRDBTestCase { } func testAnyCursorFromCursor() { - let base = IteratorCursor([0, 1]) + let base = AnyCursor([0, 1]) // This helper function makes sure AnyCursor initializer accepts any cursor, - // and not only IteratorCursor: + // and not only AnyCursor: func makeAnyCursor(_ cursor: C) -> AnyCursor where C.Element == Int { return AnyCursor(cursor) } @@ -75,4 +75,20 @@ class AnyCursorTests: GRDBTestCase { XCTFail() } } + + func testAnyCursorFromIterator() { + let cursor = AnyCursor(iterator: [0, 1].makeIterator()) + XCTAssertEqual(try cursor.next()!, 0) + XCTAssertEqual(try cursor.next()!, 1) + XCTAssertTrue(try cursor.next() == nil) // end + XCTAssertTrue(try cursor.next() == nil) // past the end + } + + func testAnyCursorFromSequence() { + let cursor = AnyCursor([0, 1]) + XCTAssertEqual(try cursor.next()!, 0) + XCTAssertEqual(try cursor.next()!, 1) + XCTAssertTrue(try cursor.next() == nil) // end + XCTAssertTrue(try cursor.next() == nil) // past the end + } } diff --git a/Tests/GRDBTests/CursorTests.swift b/Tests/GRDBTests/CursorTests.swift index 81debde5d..f73f99419 100644 --- a/Tests/GRDBTests/CursorTests.swift +++ b/Tests/GRDBTests/CursorTests.swift @@ -12,15 +12,15 @@ private struct TestError : Error { } class CursorTests: GRDBTestCase { func testContainsEquatable() { - XCTAssertTrue(try IteratorCursor([1, 2]).contains(1)) - XCTAssertFalse(try IteratorCursor([1, 2]).contains(3)) + XCTAssertTrue(try AnyCursor([1, 2]).contains(1)) + XCTAssertFalse(try AnyCursor([1, 2]).contains(3)) } func testContainsClosure() { - XCTAssertTrue(try IteratorCursor([1, 2]).contains { $0 == 1 }) - XCTAssertFalse(try IteratorCursor([1, 2]).contains { $0 == 3 }) + XCTAssertTrue(try AnyCursor([1, 2]).contains { $0 == 1 }) + XCTAssertFalse(try AnyCursor([1, 2]).contains { $0 == 3 }) do { - _ = try IteratorCursor([1, 2]).contains { _ -> Bool in throw TestError() } + _ = try AnyCursor([1, 2]).contains { _ -> Bool in throw TestError() } XCTFail() } catch is TestError { } catch { @@ -29,10 +29,10 @@ class CursorTests: GRDBTestCase { } func testDropLast() { - XCTAssertTrue(try IteratorCursor([1, 2, 3, 4, 5]).dropLast(0) == [1, 2, 3, 4, 5]) - XCTAssertTrue(try IteratorCursor([1, 2, 3, 4, 5]).dropLast(2) == [1, 2, 3]) - XCTAssertTrue(try IteratorCursor([1, 2, 3, 4, 5]).dropLast(10) == []) - XCTAssertTrue(try IteratorCursor([1, 2, 3, 4, 5]).dropLast() == [1, 2, 3, 4]) + XCTAssertTrue(try AnyCursor([1, 2, 3, 4, 5]).dropLast(0) == [1, 2, 3, 4, 5]) + XCTAssertTrue(try AnyCursor([1, 2, 3, 4, 5]).dropLast(2) == [1, 2, 3]) + XCTAssertTrue(try AnyCursor([1, 2, 3, 4, 5]).dropLast(10) == []) + XCTAssertTrue(try AnyCursor([1, 2, 3, 4, 5]).dropLast() == [1, 2, 3, 4]) } func testContainsIsLazy() { @@ -55,8 +55,8 @@ class CursorTests: GRDBTestCase { } func testFirst() { - XCTAssertEqual(try IteratorCursor([1, 2]).first { $0 == 1 }!, 1) - XCTAssertTrue(try IteratorCursor([1, 2]).first { $0 == 3 } == nil) + XCTAssertEqual(try AnyCursor([1, 2]).first { $0 == 1 }!, 1) + XCTAssertTrue(try AnyCursor([1, 2]).first { $0 == 3 } == nil) } func testFirstIsLazy() { @@ -80,14 +80,14 @@ class CursorTests: GRDBTestCase { #if swift(>=4.1) func testCompactMap() { - let cursor = IteratorCursor(["1", "foo", "2"]).compactMap { Int($0) } + let cursor = AnyCursor(["1", "foo", "2"]).compactMap { Int($0) } XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssertTrue(try cursor.next() == nil) // end } #else func testFlatMapOfOptional() { - let cursor = IteratorCursor(["1", "foo", "2"]).flatMap { Int($0) } + let cursor = AnyCursor(["1", "foo", "2"]).flatMap { Int($0) } XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssertTrue(try cursor.next() == nil) // end @@ -95,7 +95,7 @@ class CursorTests: GRDBTestCase { #endif func testForEach() throws { - let cursor = IteratorCursor([1, 2]) + let cursor = AnyCursor([1, 2]) var ints: [Int] = [] try cursor.forEach { ints.append($0) } XCTAssertEqual(ints, [1, 2]) @@ -121,66 +121,66 @@ class CursorTests: GRDBTestCase { func testJoinedWithSeparator() throws { do { - let x = try IteratorCursor([String]()).joined() + let x = try AnyCursor([String]()).joined() XCTAssertEqual(x, "") } do { - let x = try IteratorCursor([String]()).joined(separator: "><") + let x = try AnyCursor([String]()).joined(separator: "><") XCTAssertEqual(x, "") } do { - let x = try IteratorCursor(["foo"]).joined() + let x = try AnyCursor(["foo"]).joined() XCTAssertEqual(x, "foo") } do { - let x = try IteratorCursor(["foo"]).joined(separator: "><") + let x = try AnyCursor(["foo"]).joined(separator: "><") XCTAssertEqual(x, "foo") } do { - let x = try IteratorCursor(["foo", "bar", "baz"]).joined() + let x = try AnyCursor(["foo", "bar", "baz"]).joined() XCTAssertEqual(x, "foobarbaz") } do { - let x = try IteratorCursor(["foo", "bar", "baz"]).joined(separator: "><") + let x = try AnyCursor(["foo", "bar", "baz"]).joined(separator: "><") XCTAssertEqual(x, "foo>), 1) + XCTAssertEqual(try AnyCursor([1, 2, 3]).max(), 3) + XCTAssertEqual(try AnyCursor([1, 2, 3]).max(by: >), 1) } func testMin() { - XCTAssertEqual(try IteratorCursor([1, 2, 3]).min(), 1) - XCTAssertEqual(try IteratorCursor([1, 2, 3]).min(by: >), 3) + XCTAssertEqual(try AnyCursor([1, 2, 3]).min(), 1) + XCTAssertEqual(try AnyCursor([1, 2, 3]).min(by: >), 3) } func testReduce() throws { - let cursor = IteratorCursor([1, 2]) + let cursor = AnyCursor([1, 2]) let squareSum = try cursor.reduce(0) { (acc, int) in acc + int * int } XCTAssertEqual(squareSum, 5) } func testReduceInto() throws { - let cursor = IteratorCursor([1, 2]) + let cursor = AnyCursor([1, 2]) let squareSum = try cursor.reduce(into: 0) { (acc, int) in acc += int * int } XCTAssertEqual(squareSum, 5) } func testSuffix() throws { do { - let cursor = IteratorCursor([1, 2, 3, 4, 5]) + let cursor = AnyCursor([1, 2, 3, 4, 5]) let suffix = try cursor.suffix(0) XCTAssertTrue(suffix == []) } do { - let cursor = IteratorCursor([1, 2, 3, 4, 5]) + let cursor = AnyCursor([1, 2, 3, 4, 5]) let suffix = try cursor.suffix(2) XCTAssertTrue(suffix == [4, 5]) } do { - let cursor = IteratorCursor([1, 2, 3, 4, 5]) + let cursor = AnyCursor([1, 2, 3, 4, 5]) let suffix = try cursor.suffix(10) XCTAssertTrue(suffix == [1, 2, 3, 4, 5]) } diff --git a/Tests/GRDBTests/DropFirstCursorTests.swift b/Tests/GRDBTests/DropFirstCursorTests.swift index 889b21c5f..2343305c5 100644 --- a/Tests/GRDBTests/DropFirstCursorTests.swift +++ b/Tests/GRDBTests/DropFirstCursorTests.swift @@ -13,7 +13,7 @@ class DropFirstCursorTests: GRDBTestCase { func testDropFirstCursorFromCursor() throws { do { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.dropFirst(0) try XCTAssertEqual(cursor.next()!, 1) try XCTAssertEqual(cursor.next()!, 2) @@ -24,7 +24,7 @@ class DropFirstCursorTests: GRDBTestCase { XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.dropFirst(2) try XCTAssertEqual(cursor.next()!, 3) try XCTAssertEqual(cursor.next()!, 4) @@ -33,13 +33,13 @@ class DropFirstCursorTests: GRDBTestCase { XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.dropFirst(10) XCTAssertTrue(try cursor.next() == nil) // end XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.dropFirst() try XCTAssertEqual(cursor.next()!, 2) try XCTAssertEqual(cursor.next()!, 3) @@ -70,7 +70,7 @@ class DropFirstCursorTests: GRDBTestCase { } func testDropFirstChain() throws { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.dropFirst(1).dropFirst(1) try XCTAssertEqual(cursor.next()!, 3) try XCTAssertEqual(cursor.next()!, 4) diff --git a/Tests/GRDBTests/DropWhileCursorTests.swift b/Tests/GRDBTests/DropWhileCursorTests.swift index 63e9b0832..7cbcc336d 100644 --- a/Tests/GRDBTests/DropWhileCursorTests.swift +++ b/Tests/GRDBTests/DropWhileCursorTests.swift @@ -13,7 +13,7 @@ class DropWhileCursorTests: GRDBTestCase { func testDropWhileCursorFromCursor() throws { do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.drop(while: { $0 < 3 }) try XCTAssertEqual(cursor.next()!, 3) try XCTAssertEqual(cursor.next()!, 1) @@ -22,13 +22,13 @@ class DropWhileCursorTests: GRDBTestCase { XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.drop(while: { _ in true }) XCTAssertTrue(try cursor.next() == nil) // end XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.drop(while: { _ in false }) try XCTAssertEqual(cursor.next()!, 1) try XCTAssertEqual(cursor.next()!, 2) @@ -39,7 +39,7 @@ class DropWhileCursorTests: GRDBTestCase { XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.drop(while: { _ in throw TestError() }) _ = try cursor.next() XCTFail() diff --git a/Tests/GRDBTests/EnumeratedCursorTests.swift b/Tests/GRDBTests/EnumeratedCursorTests.swift index b89211877..c4625be92 100644 --- a/Tests/GRDBTests/EnumeratedCursorTests.swift +++ b/Tests/GRDBTests/EnumeratedCursorTests.swift @@ -12,7 +12,7 @@ private struct TestError : Error { } class EnumeratedCursorTests: GRDBTestCase { func testEnumeratedCursorFromCursor() throws { - let base = IteratorCursor(["foo", "bar"]) + let base = AnyCursor(["foo", "bar"]) let cursor = base.enumerated() var (n, x) = try cursor.next()! XCTAssertEqual(x, "foo") diff --git a/Tests/GRDBTests/FilterCursorTests.swift b/Tests/GRDBTests/FilterCursorTests.swift index 10b68d8f1..dbde9254e 100644 --- a/Tests/GRDBTests/FilterCursorTests.swift +++ b/Tests/GRDBTests/FilterCursorTests.swift @@ -12,7 +12,7 @@ private struct TestError : Error { } class FilterCursorTests: GRDBTestCase { func testFilterCursorFromCursor() { - let base = IteratorCursor([1, 2, 3, 4]) + let base = AnyCursor([1, 2, 3, 4]) let cursor = base.filter { $0 % 2 == 0 } XCTAssertEqual(try cursor.next()!, 2) XCTAssertEqual(try cursor.next()!, 4) @@ -39,7 +39,7 @@ class FilterCursorTests: GRDBTestCase { } func testThrowingFilterCursorFromCursor() { - let base = IteratorCursor([0, 1]) + let base = AnyCursor([0, 1]) let cursor = base.filter { if $0 > 0 { throw TestError() } return true diff --git a/Tests/GRDBTests/FlattenCursorTests.swift b/Tests/GRDBTests/FlattenCursorTests.swift index 41a160879..f2fa00338 100644 --- a/Tests/GRDBTests/FlattenCursorTests.swift +++ b/Tests/GRDBTests/FlattenCursorTests.swift @@ -10,7 +10,7 @@ import XCTest class FlattenCursorTests: GRDBTestCase { func testFlatMapOfSequence() { - let cursor = IteratorCursor([1, 2]).flatMap { [$0, $0+1] } + let cursor = AnyCursor([1, 2]).flatMap { [$0, $0+1] } XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssertEqual(try cursor.next()!, 2) @@ -20,7 +20,7 @@ class FlattenCursorTests: GRDBTestCase { } func testFlatMapOfCursor() { - let cursor = IteratorCursor([1, 2]).flatMap { IteratorCursor([$0, $0+1]) } + let cursor = AnyCursor([1, 2]).flatMap { AnyCursor([$0, $0+1]) } XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssertEqual(try cursor.next()!, 2) @@ -30,7 +30,7 @@ class FlattenCursorTests: GRDBTestCase { } func testSequenceFlatMapOfCursor() { - let cursor = [1, 2].flatMap { IteratorCursor([$0, $0+1]) } + let cursor = [1, 2].flatMap { AnyCursor([$0, $0+1]) } XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssertEqual(try cursor.next()!, 2) @@ -40,7 +40,7 @@ class FlattenCursorTests: GRDBTestCase { } func testJoinedSequences() { - let cursor = IteratorCursor([[1, 2], [2, 3]]).joined() + let cursor = AnyCursor([[1, 2], [2, 3]]).joined() XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssertEqual(try cursor.next()!, 2) @@ -50,7 +50,7 @@ class FlattenCursorTests: GRDBTestCase { } func testJoinedCursors() { - let cursor = IteratorCursor([IteratorCursor([1, 2]), IteratorCursor([2, 3])]).joined() + let cursor = AnyCursor([AnyCursor([1, 2]), AnyCursor([2, 3])]).joined() XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 2) XCTAssertEqual(try cursor.next()!, 2) diff --git a/Tests/GRDBTests/IteratorCursorTests.swift b/Tests/GRDBTests/IteratorCursorTests.swift deleted file mode 100644 index 39b01dd8f..000000000 --- a/Tests/GRDBTests/IteratorCursorTests.swift +++ /dev/null @@ -1,27 +0,0 @@ -import XCTest -#if GRDBCIPHER - import GRDBCipher -#elseif GRDBCUSTOMSQLITE - import GRDBCustomSQLite -#else - import GRDB -#endif - -class IteratorCursorTests: GRDBTestCase { - - func testIteratorCursorFromIterator() { - let cursor = IteratorCursor([0, 1].makeIterator()) - XCTAssertEqual(cursor.next()!, 0) - XCTAssertEqual(cursor.next()!, 1) - XCTAssertTrue(cursor.next() == nil) // end - XCTAssertTrue(cursor.next() == nil) // past the end - } - - func testIteratorCursorFromSequence() { - let cursor = IteratorCursor([0, 1]) - XCTAssertEqual(cursor.next()!, 0) - XCTAssertEqual(cursor.next()!, 1) - XCTAssertTrue(cursor.next() == nil) // end - XCTAssertTrue(cursor.next() == nil) // past the end - } -} diff --git a/Tests/GRDBTests/MapCursorTests.swift b/Tests/GRDBTests/MapCursorTests.swift index 52789379c..56a647325 100644 --- a/Tests/GRDBTests/MapCursorTests.swift +++ b/Tests/GRDBTests/MapCursorTests.swift @@ -12,7 +12,7 @@ private struct TestError : Error { } class MapCursorTests: GRDBTestCase { func testMap() { - let base = IteratorCursor([1, 2]) + let base = AnyCursor([1, 2]) let cursor = base.map { $0 * $0 } XCTAssertEqual(try cursor.next()!, 1) XCTAssertEqual(try cursor.next()!, 4) diff --git a/Tests/GRDBTests/PrefixCursorTests.swift b/Tests/GRDBTests/PrefixCursorTests.swift index fdffab97d..5ee9d2094 100644 --- a/Tests/GRDBTests/PrefixCursorTests.swift +++ b/Tests/GRDBTests/PrefixCursorTests.swift @@ -13,13 +13,13 @@ class PrefixCursorTests: GRDBTestCase { func testPrefixCursorFromCursor() throws { do { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.prefix(0) XCTAssertTrue(try cursor.next() == nil) // end XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.prefix(2) try XCTAssertEqual(cursor.next()!, 1) try XCTAssertEqual(cursor.next()!, 2) @@ -27,7 +27,7 @@ class PrefixCursorTests: GRDBTestCase { XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.prefix(10) try XCTAssertEqual(cursor.next()!, 1) try XCTAssertEqual(cursor.next()!, 2) @@ -60,7 +60,7 @@ class PrefixCursorTests: GRDBTestCase { } func testPrefixCursorChain() throws { - let base = IteratorCursor([1, 2, 3, 4, 5]) + let base = AnyCursor([1, 2, 3, 4, 5]) let cursor = base.prefix(2).prefix(1) try XCTAssertEqual(cursor.next()!, 1) XCTAssertTrue(try cursor.next() == nil) // end diff --git a/Tests/GRDBTests/PrefixWhileCursorTests.swift b/Tests/GRDBTests/PrefixWhileCursorTests.swift index 9c0228938..9300b5faf 100644 --- a/Tests/GRDBTests/PrefixWhileCursorTests.swift +++ b/Tests/GRDBTests/PrefixWhileCursorTests.swift @@ -13,7 +13,7 @@ class PrefixWhileCursorTests: GRDBTestCase { func testPrefixWhileCursorFromCursor() throws { do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.prefix(while: { $0 < 3 }) try XCTAssertEqual(cursor.next()!, 1) try XCTAssertEqual(cursor.next()!, 2) @@ -21,7 +21,7 @@ class PrefixWhileCursorTests: GRDBTestCase { XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.prefix(while: { _ in true }) try XCTAssertEqual(cursor.next()!, 1) try XCTAssertEqual(cursor.next()!, 2) @@ -32,13 +32,13 @@ class PrefixWhileCursorTests: GRDBTestCase { XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.prefix(while: { _ in false }) XCTAssertTrue(try cursor.next() == nil) // end XCTAssertTrue(try cursor.next() == nil) // past the end } do { - let base = IteratorCursor([1, 2, 3, 1, 5]) + let base = AnyCursor([1, 2, 3, 1, 5]) let cursor = base.prefix(while: { _ in throw TestError() }) _ = try cursor.next() XCTFail()