Created
March 2, 2017 14:21
-
-
Save Otbivnoe/da76211d5650bc7d9a5ca97f09f2a560 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
extension ObservableType { | |
func flatMap<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> { | |
return flatMap { [weak obj] value -> Observable<O.E> in | |
try obj.map { try selector($0, value).asObservable() } ?? .empty() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could use
O: ObservableConvertibleType
instead ofO: ObservableType
. It would make possible to use, for instance,Driver
without the need to useasObservable()
in selector.