infallible public

This commit is contained in:
freak4pc 2020-10-04 08:57:05 +03:00 committed by Shai Mishali
parent 2ff7b9ff40
commit e85180a704

View File

@ -6,15 +6,29 @@
// Copyright © 2020 Krunoslav Zaher. All rights reserved.
//
extension ObservableConvertibleType {
public extension ObservableConvertibleType {
/// Convert to an `Infallible`
///
/// - returns: `Infallible<Element>`
func asInfallible(onErrorJustReturn element: Element) -> Infallible<Element> {
Infallible(self.asObservable().catchAndReturn(element))
}
/// Convert to an `Infallible`
///
/// - parameter onErroFallbackTo: Fall back to this provided infallible on error
///
///
/// - returns: `Infallible<Element>`
func asInfallible(onErrorFallbackTo infallible: Infallible<Element>) -> Infallible<Element> {
Infallible(self.asObservable().catch { _ in infallible.asObservable() })
}
/// Convert to an `Infallible`
///
/// - parameter onErrorRecover: Recover with the this infallible closure
///
/// - returns: `Infallible<Element>`
func asInfallible(onErrorRecover: @escaping (Swift.Error) -> Infallible<Element>) -> Infallible<Element> {
Infallible(asObservable().catch { onErrorRecover($0).asObservable() })
}