File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -410,10 +410,15 @@ extension CasePathable {
410
410
/// userActions.filter { $0.is(\.home) } // [UserAction.home(.onAppear)]
411
411
/// userActions.filter { $0.is(\.settings) } // [UserAction.settings(.subscribeButtonTapped)]
412
412
/// ```
413
+ @_disfavoredOverload
413
414
public func `is`( _ keyPath: PartialCaseKeyPath < Self > ) -> Bool {
414
415
self [ case: keyPath] != nil
415
416
}
416
417
418
+ public func `is`< Wrapped> ( _ keyPath: CaseKeyPath < Self , Wrapped ? > ) -> Bool {
419
+ self [ case: keyPath] != nil
420
+ }
421
+
417
422
/// Unwraps and yields a mutable associated value to a closure.
418
423
///
419
424
/// > Warning: If the enum's case does not match the given case key path, the mutation will not be
Original file line number Diff line number Diff line change @@ -132,14 +132,14 @@ final class CasePathsTests: XCTestCase {
132
132
func testMatch( ) {
133
133
switch Foo . bar ( . int( 42 ) ) {
134
134
case \. bar. int:
135
- return
135
+ break
136
136
default :
137
137
XCTFail ( )
138
138
}
139
139
140
140
switch Foo . bar ( . int( 42 ) ) {
141
141
case \. bar:
142
- return
142
+ break
143
143
default :
144
144
XCTFail ( )
145
145
}
@@ -150,6 +150,10 @@ final class CasePathsTests: XCTestCase {
150
150
XCTAssertFalse ( Foo . bar ( . int( 42 ) ) . is ( \. baz. string) )
151
151
XCTAssertFalse ( Foo . bar ( . int( 42 ) ) . is ( \. blob) )
152
152
XCTAssertFalse ( Foo . bar ( . int( 42 ) ) . is ( \. fizzBuzz) )
153
+ XCTAssertTrue ( Foo . foo ( nil ) . is ( \. foo) )
154
+ XCTAssertTrue ( Foo . foo ( nil ) . is ( \. foo. none) )
155
+ XCTAssertTrue ( Foo . foo ( " " ) . is ( \. foo) )
156
+ XCTAssertFalse ( Foo . foo ( nil ) . is ( \. bar) )
153
157
}
154
158
155
159
func testPartialCaseKeyPath( ) {
@@ -169,6 +173,7 @@ final class CasePathsTests: XCTestCase {
169
173
case baz( Baz )
170
174
case fizzBuzz
171
175
case blob( Blob )
176
+ case foo( String ? )
172
177
}
173
178
@CasePathable @dynamicMemberLookup enum Bar : Equatable {
174
179
case int( Int )
You can’t perform that action at this time.
0 commit comments