Created
June 15, 2016 21:06
-
-
Save gravicle/8fd14b940e97e6d4bc7ecfec3703fd2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Foundation | |
import RxSwift | |
protocol OptionalType { | |
associatedtype Wrapped | |
var value: Wrapped? { get } | |
} | |
extension Optional: OptionalType { | |
var value: Wrapped? { | |
return self | |
} | |
} | |
extension Observable where Element: OptionalType { | |
func filterNil() -> Observable<Element.Wrapped> { | |
return flatMap { (element) -> Observable<Element.Wrapped> in | |
if let value = element.value { | |
return .just(value) | |
} else { | |
return .empty() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only works for observables which have optional values.