1
1
extension Optional : CasePathable {
2
- @dynamicMemberLookup
3
2
public struct AllCasePaths {
3
+ /// A case path to the absence of a value.
4
4
public var none : AnyCasePath < Optional , Void > {
5
5
AnyCasePath (
6
6
embed: { . none } ,
@@ -11,6 +11,7 @@ extension Optional: CasePathable {
11
11
)
12
12
}
13
13
14
+ /// A case path to the presence of a value.
14
15
public var some : AnyCasePath < Optional , Wrapped > {
15
16
AnyCasePath (
16
17
embed: { . some( $0) } ,
@@ -20,20 +21,6 @@ extension Optional: CasePathable {
20
21
}
21
22
)
22
23
}
23
-
24
- public subscript< Member> (
25
- dynamicMember keyPath: KeyPath < Wrapped . AllCasePaths , AnyCasePath < Wrapped , Member > >
26
- ) -> AnyCasePath < Optional , Member >
27
- where Wrapped: CasePathable {
28
- let casePath = Wrapped . allCasePaths [ keyPath: keyPath]
29
- return AnyCasePath (
30
- embed: { . some( casePath. embed ( $0) ) } ,
31
- extract: {
32
- guard case let . some( value) = $0 else { return nil }
33
- return casePath. extract ( from: value)
34
- }
35
- )
36
- }
37
24
}
38
25
39
26
public static var allCasePaths : AllCasePaths {
@@ -42,6 +29,10 @@ extension Optional: CasePathable {
42
29
}
43
30
44
31
extension Case {
32
+ /// A case path to the presence of a nested value.
33
+ ///
34
+ /// This subscript can chain into an optional's wrapped value without explicitly specifying each
35
+ /// `some` component.
45
36
public subscript< Member> (
46
37
dynamicMember keyPath: KeyPath < Value . AllCasePaths , AnyCasePath < Value , Member ? > >
47
38
) -> Case < Member >
0 commit comments