Last active
January 31, 2020 09:28
-
-
Save amirdew/2b48435e0b6b51605131d0c9b48dd84d 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 | |
extension Observable where Element: OptionalType { | |
func ignoreNil() -> Observable<Element.T> { | |
filter { $0.optional != nil }.map { $0.optional! } | |
} | |
} | |
extension Observable { | |
func compactMap<R: OptionalType>(_ transform: @escaping (Observable.E) throws -> R) -> Observable<R.T> { | |
map(transform).ignoreNil() | |
} | |
} | |
protocol OptionalType { | |
associatedtype T | |
var optional: T? { get } | |
} | |
extension Optional: OptionalType { | |
var optional: Wrapped? { self } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment