|
| 1 | +extension CasePath { |
| 2 | + /// Returns a case path for the given embed function. |
| 3 | + /// |
| 4 | + /// - Note: This operator is only intended to be used with enum cases that have no associated |
| 5 | + /// values. Its behavior is otherwise undefined. |
| 6 | + /// - Parameter embed: An embed function. |
| 7 | + /// - Returns: A case path. |
| 8 | + public init(_ embed: @escaping (Value) -> Root) { |
| 9 | + self.init(embed: embed, extract: extractHelp(embed)) |
| 10 | + } |
| 11 | + |
| 12 | + /// Returns a case path for the given embed function. |
| 13 | + /// |
| 14 | + /// - Note: This operator is only intended to be used with enum cases that have no associated |
| 15 | + /// values. Its behavior is otherwise undefined. |
| 16 | + /// - Parameter embed: An embed function. |
| 17 | + /// - Returns: A case path. |
| 18 | + public init<Wrapped>(_ embed: @escaping (Value) -> Root) where Root == Wrapped? { |
| 19 | + self.init(embed: embed, extract: optionalPromotedExtractHelp(embed)) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +extension CasePath where Value == Void { |
| 24 | + /// Returns a void case path for a case with no associated value. |
| 25 | + /// |
| 26 | + /// - Note: This operator is only intended to be used with enum cases that have no associated |
| 27 | + /// values. Its behavior is otherwise undefined. |
| 28 | + /// - Parameter root: A case with no an associated value. |
| 29 | + /// - Returns: A void case path. |
| 30 | + public init(_ root: Root) { |
| 31 | + self.init(embed: { root }, extract: extractVoidHelp(root)) |
| 32 | + } |
| 33 | + |
| 34 | + /// Returns a void case path for a case with no associated value. |
| 35 | + /// |
| 36 | + /// - Note: This operator is only intended to be used with enum cases that have no associated |
| 37 | + /// values. Its behavior is otherwise undefined. |
| 38 | + /// - Parameter root: A case with no an associated value. |
| 39 | + /// - Returns: A void case path. |
| 40 | + public init<Wrapped>(_ root: Root) where Root == Wrapped? { |
| 41 | + self.init(embed: { root }, extract: optionalPromotedExtractVoidHelp(root)) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +extension CasePath where Root == Value { |
| 46 | + /// Returns the identity case path for the given type. Enables `CasePath(MyType.self)` syntax. |
| 47 | + /// |
| 48 | + /// - Parameter type: A type for which to return the identity case path. |
| 49 | + /// - Returns: An identity case path. |
| 50 | + public init(_ type: Root.Type) { |
| 51 | + self = .self |
| 52 | + } |
| 53 | +} |
| 54 | + |
1 | 55 | extension CasePath { |
2 | 56 | /// Returns a case path that extracts values associated with a given enum case initializer. |
3 | 57 | /// |
|
0 commit comments