Skip to content

Instantly share code, notes, and snippets.

@Otbivnoe
Created March 2, 2017 14:21
Show Gist options
  • Save Otbivnoe/da76211d5650bc7d9a5ca97f09f2a560 to your computer and use it in GitHub Desktop.
Save Otbivnoe/da76211d5650bc7d9a5ca97f09f2a560 to your computer and use it in GitHub Desktop.
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()
}
}
}
@dsk1306
Copy link

dsk1306 commented Feb 12, 2019

You could use O: ObservableConvertibleType instead of O: ObservableType. It would make possible to use, for instance, Driver without the need to use asObservable() in selector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment