Last active
July 23, 2019 08:12
-
-
Save Otbivnoe/12a9f0cb1e2280659dbfee2e6b3833ae 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() | |
} | |
} | |
func flatMapFirst<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> { | |
return flatMapFirst { [weak obj] value -> Observable<O.E> in | |
try obj.map { try selector($0, value).asObservable() } ?? .empty() | |
} | |
} | |
func flatMapWithIndex<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E, Int) throws -> O) -> Observable<O.E> { | |
return flatMapWithIndex { [weak obj] value, index -> Observable<O.E> in | |
try obj.map { try selector($0, value, index).asObservable() } ?? .empty() | |
} | |
} | |
func flatMapLatest<A: AnyObject, O: ObservableType>(weak obj: A, selector: @escaping (A, Self.E) throws -> O) -> Observable<O.E> { | |
return flatMapLatest { [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