Closed SeRG1k17 closed 3 years ago
Also, I think, useful operator:
public extension Publisher { func fromResult<T, E>() -> AnyPublisher<T, E> where Self.Failure == Never, Self.Output == Result<T, E>, E: Error { setFailureType(to: E.self) .flatMap { (result: Self.Output) -> AnyPublisher<T, E> in switch result { case .success(let element): return Just(element) .setFailureType(to: E.self) .eraseToAnyPublisher() case .failure(let error): return Fail(error: error) .eraseToAnyPublisher() } } .eraseToAnyPublisher() } }
Added in 1.5.0
Good to know it :) Both operators?
No, we don't usually accept operators this way - it needs a separate PR and use cases so we can discuss :)
Thanks !
I wll prepare PR soon. Please, close it
Also, I think, useful operator: