Last active
December 4, 2017 02:13
-
-
Save zzdjk6/197eab7c1dc3982f18b971c6bb3c885b to your computer and use it in GitHub Desktop.
Compatible Layer: Commonly used Operations in RxSwift 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension ObservableType { | |
public func subscribeNext(_ onNext: ((Self.E) -> Swift.Void)? = nil) -> Disposable { | |
return self.subscribe(onNext: onNext, onError: nil, onCompleted: nil, onDisposed: nil) | |
} | |
public func doOnNext(_ onNext: ((Self.E) -> (Swift.Void))? = nil) -> Observable<E> { | |
return self.do( | |
onNext: { (element) in | |
onNext?(element) | |
}, | |
onError: nil, | |
onCompleted: nil, | |
onSubscribe: nil, | |
onSubscribed: nil, | |
onDispose: nil) | |
} | |
public func doOnError(_ onError: ((Swift.Error) -> Swift.Void)? = nil) -> Observable<E> { | |
return self.do( | |
onNext: nil, | |
onError: { (error) in | |
onError?(error) | |
}, | |
onCompleted: nil, | |
onSubscribe: nil, | |
onSubscribed: nil, | |
onDispose: nil) | |
} | |
public func doOnCompleted(_ onCompleted: ((Swift.Void) -> (Swift.Void))? = nil) -> Observable<E> { | |
return self.do( | |
onNext: nil, | |
onError: nil, | |
onCompleted: { | |
onCompleted?() | |
}, | |
onSubscribe: nil, | |
onSubscribed: nil, onDispose: nil) | |
} | |
public func doOnErrorAndCompleted(_ onErrorAndCompleted: ((Swift.Void) -> (Swift.Void))? = nil) -> Observable<E> { | |
return self.do( | |
onNext: nil, | |
onError: { _ in | |
onErrorAndCompleted?() | |
}, | |
onCompleted: { | |
onErrorAndCompleted?() | |
}, | |
onSubscribe: nil, | |
onSubscribed: nil, onDispose: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment