Created
May 3, 2016 13:20
-
-
Save ivanbruel/24e59d0748f9007fa68be41ccbee4a34 to your computer and use it in GitHub Desktop.
RxSwift extension to handle Result signals with doOn methods
This file contains hidden or 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 Foundation | |
import RxSwift | |
import Result | |
extension ObservableType where E: ResultType { | |
func doOnSuccess(onSuccess: (E.Value throws -> Void)) | |
-> Observable<E> { | |
return self.doOnNext { (value) in | |
guard let successValue = value.value else { | |
return | |
} | |
try onSuccess(successValue) | |
} | |
} | |
func doOnFailure(onFailure: (E.Error throws -> Void)) | |
-> Observable<E> { | |
return self.doOnNext { (value) in | |
guard let failureValue = value.error else { | |
return | |
} | |
try onFailure(failureValue) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment