Skip to content

Instantly share code, notes, and snippets.

@artemnovichkov
Last active January 30, 2017 02:12
Show Gist options
  • Save artemnovichkov/44a4354899cfd964b7258012965abe0c to your computer and use it in GitHub Desktop.
Save artemnovichkov/44a4354899cfd964b7258012965abe0c to your computer and use it in GitHub Desktop.
Syntax sugar for ObservableType
import RxSwift
extension ObservableType {
typealias EmptyHandler = () -> Void
func onNext(_ onNext: @escaping (E) -> Void) -> Observable<E> {
return `do`(onNext: onNext)
}
func onError(_ onError: @escaping (Error) -> Void) -> Observable<E> {
return `do`(onError: onError)
}
func onCompleted(_ onCompleted: @escaping EmptyHandler) -> Observable<E> {
return `do`(onCompleted: onCompleted)
}
func onDispose(_ onDispose: @escaping EmptyHandler) -> Observable<E> {
return `do`(onDispose: onDispose)
}
}
//Example:
// Observable.just(3)
// .onNext { value in
// print(value)
// }
// .onError { error in
// print(error.localizedDescription)
// }
// .subscribe()
// .addDisposableTo(disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment