Skip to content

Instantly share code, notes, and snippets.

@loromits
Created December 4, 2018 12:55
Show Gist options
  • Save loromits/5c5330fc8541506ddb43bbfcb1c7c13a to your computer and use it in GitHub Desktop.
Save loromits/5c5330fc8541506ddb43bbfcb1c7c13a to your computer and use it in GitHub Desktop.
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