Skip to content

Commit 26beaa5

Browse files
committed
Added CurrentValuePublisher.map(_:) overload for key paths for Swift <6.0
1 parent bce5b76 commit 26beaa5

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Sources/CombineExtensions/CurrentValuePublisher/CurrentValuePublisher+Map.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,25 @@ extension CurrentValuePublisher {
2424
}
2525

2626
}
27+
28+
#if compiler(<6.0)
29+
30+
extension CurrentValuePublisher {
31+
32+
/// Produces a new `CurrentValuePublisher` by extracting a value from the current and all
33+
/// subsequent values using the given key path.
34+
///
35+
/// This overload is provided for Swift versions prior to 6.0, where key path inference
36+
/// in `map` is not fully supported.
37+
///
38+
/// - Parameter keyPath: A key path to extract a property of a value.
39+
/// - Returns: A `CurrentValuePublisher` that emits the values extracted by the given key path.
40+
public func map<T>(
41+
_ keyPath: KeyPath<Output, T>
42+
) -> CurrentValuePublisher<T, Failure> {
43+
self.map { $0[keyPath: keyPath] }
44+
}
45+
46+
}
47+
48+
#endif

0 commit comments

Comments
 (0)