Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Last active December 4, 2017 02:13
Show Gist options
  • Save zzdjk6/197eab7c1dc3982f18b971c6bb3c885b to your computer and use it in GitHub Desktop.
Save zzdjk6/197eab7c1dc3982f18b971c6bb3c885b to your computer and use it in GitHub Desktop.
Compatible Layer: Commonly used Operations in RxSwift 2.x
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