Skip to content

Instantly share code, notes, and snippets.

@CedricGatay
Created February 8, 2018 10:44
Show Gist options
  • Save CedricGatay/7360c31989123f9df128f19016cdce23 to your computer and use it in GitHub Desktop.
Save CedricGatay/7360c31989123f9df128f19016cdce23 to your computer and use it in GitHub Desktop.
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