Avatar
@koher futureMapだと元々のMapの機能とか失っちゃってかなり勿体無いので protocol FutureLike { associatedtype Output associatedtype Failure: Error func asFuture() -> Future<Output, Failure> } こういうの作って extension Publishers.Map: FutureLike where Upstream: FutureLike { func asFuture() -> Future<Output, Upstream.Failure> { Future(self) } } こうした方が良いですね
3:53 AM
MapやTryMapはoverloadが充実していて、実行時にエコな仕組みがあるので(これはRxSwiftにもある仕組み) @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension Publishers.Map { public func map<T>(_ transform: @escaping (Output) -> T) -> Publishers.Map<Upstream, T> public func tryMap<T>(_ transform: @escaping (Output) throws -> T) -> Publishers.TryMap<Upstream, T> } @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension Publishers.TryMap { public func map<T>(_ transform: @escaping (Output) -> T) -> Publishers.TryMap<Upstream, T> public func tryMap<T>(_ transform: @escaping (Output) throws -> T) -> Publishers.TryMap<Upstream, T> } (edited)