Last active
January 30, 2017 02:12
-
-
Save artemnovichkov/44a4354899cfd964b7258012965abe0c to your computer and use it in GitHub Desktop.
Syntax sugar for ObservableType
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
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