Created
February 8, 2018 10:44
-
-
Save CedricGatay/7360c31989123f9df128f19016cdce23 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 | |
// trick to get a clean unwrap optional by creating an intermediate type | |
protocol Optionable { | |
associatedtype Wrapped | |
var value: Wrapped? { get } | |
} | |
extension Optional : Optionable { | |
var value: Wrapped? { return self } | |
} | |
extension ObservableType where Self.E : Optionable { | |
func flatten() -> Observable<Self.E.Wrapped> { | |
return filter { $0.value != nil} .map { $0.value! } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment