Last active
June 2, 2019 18:24
-
-
Save M0rtyMerr/2ff887af6e16f768ce0cd909f731d86a to your computer and use it in GitHub Desktop.
Small useful operators from RxSwiftExt, my top-3.
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
//______ unwrap | |
Observable.from([1, 2, nil, 4]) | |
.unwrap() | |
.bind { print($0) } | |
// Output: 1, 2, 4 | |
//______ filterMap | |
Observable.of(1, 2, 3, 4, 5, 6) | |
.filterMap { $0 % 2 == 0 ? .map($0 * 2) : .ignore } | |
// Output: 4, 8, 12 | |
//______ apply | |
func requestPolicy(_ request: Single<Response>) -> Single<Response> { | |
return request.retry(maxAttempts) | |
.do(onNext: sideEffect) | |
.map { Response.success } | |
.catchError { error in Observable.just(parseRequestError(error: error)) } | |
} | |
let resilientRequest = request.apply(requestPolicy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment