BREAKING: turn Cursor.isEmpty into a property

https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md
This commit is contained in:
Gwendal Roué committed 2022-08-21 21:22:34 +02:00
1 parent 180c8975ac
commit dba7f1b2dc
4 files changed
+21 -4

No files matched your search

+1
View File
@@ -100,6 +100,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
- **Breaking**: Removed deprecated methods
- **Breaking**: The in-memory `DatabaseQueue()` initializer can now throw errors.
- **Breaking**: The `selectID()` method is replaced with `selectPrimaryKey(as:)`.
- **Breaking**: `Cursor.isEmpty` is now a throwing property, instead of a method.
- **New**: Request protocols and cursors now define primary associated types, enabled by [SE-0346](https://github.com/apple/swift-evolution/blob/main/proposals/0346-light-weight-same-type-syntax.md).
## 5.26.0
+7
View File
@@ -60,3 +60,10 @@ The `Cursor` protocol has also gained a primary associated type (the type of its
}
}
```
- `Cursor.isEmpty` is now a throwing property, instead of a method:
```diff
-if try cursor.isEmpty() { ... }
+if try cursor.isEmpty { ... }
```
+6 -4
View File
@@ -243,10 +243,12 @@ public protocol Cursor<Element>: AnyObject {
}
extension Cursor {
/// Returns a Boolean value indicating whether the cursor contains
/// an element.
public func isEmpty() throws -> Bool {
try next() == nil
/// Returns a Boolean value indicating whether the cursor does not contain
/// any element.
///
/// - important: This property may consume elements.
public var isEmpty: Bool {
get throws { try next() == nil }
}
/// Returns a Boolean value indicating whether the cursor contains an
+7
View File
@@ -5,13 +5,20 @@ private struct TestError : Error { }
class CursorTests: GRDBTestCase {
func testIsEmpty() {
XCTAssertTrue(try AnyCursor([Int]()).isEmpty)
XCTAssertFalse(try AnyCursor([1]).isEmpty)
}
func testContainsEquatable() {
XCTAssertTrue(try AnyCursor([1, 2]).contains(1))
XCTAssertTrue(try AnyCursor([1, 2]).contains(2))
XCTAssertFalse(try AnyCursor([1, 2]).contains(3))
}
func testContainsClosure() {
XCTAssertTrue(try AnyCursor([1, 2]).contains { $0 == 1 })
XCTAssertTrue(try AnyCursor([1, 2]).contains { $0 == 2 })
XCTAssertFalse(try AnyCursor([1, 2]).contains { $0 == 3 })
do {
_ = try AnyCursor([1, 2]).contains { _ -> Bool in throw TestError() }