Created
December 4, 2018 12:55
-
-
Save loromits/5c5330fc8541506ddb43bbfcb1c7c13a to your computer and use it in GitHub Desktop.
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 | |
struct MaybeNever<S: AnyObject> { | |
private weak var take: S? | |
init(_ t: S) { | |
take = t | |
} | |
func run<A, B, R>(_ f: @escaping (S, A, B) -> Observable<R>) -> (A, B) -> Observable<R> { | |
return { a, b in | |
if let t = self.take { | |
return f(t, a, b) | |
} | |
return .never() | |
} | |
} | |
} | |
someValues.flatMapLatest(MaybeNever(self).run { $0.sendRequest(value1: $1, value2: $2) })... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment