CombineCommunity / CombineExt

CombineExt provides a collection of operators, publishers and utilities for Combine, that are not provided by Apple themselves, but are common in other Reactive Frameworks and standards.
https://combine.community
MIT License
1.73k stars 155 forks source link

MapToResult operator was not added to 1.3.0 release #103

Closed SeRG1k17 closed 3 years ago

SeRG1k17 commented 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()
    }
}
freak4pc commented 3 years ago

Added in 1.5.0

SeRG1k17 commented 3 years ago

Good to know it :) Both operators?

freak4pc commented 3 years ago

No, we don't usually accept operators this way - it needs a separate PR and use cases so we can discuss :)

Thanks !

SeRG1k17 commented 3 years ago

I wll prepare PR soon. Please, close it