Skip to content

Instantly share code, notes, and snippets.

@ukitaka
Created July 8, 2016 10:09
Show Gist options
  • Save ukitaka/ca117bc3bf3db83fcdf336b1d25e8248 to your computer and use it in GitHub Desktop.
Save ukitaka/ca117bc3bf3db83fcdf336b1d25e8248 to your computer and use it in GitHub Desktop.
protocol OptionalType {
associatedtype Wrapped
func map<U>(@noescape f: (Wrapped) throws -> U) rethrows -> U?
}
extension Optional: OptionalType {
}
extension ObservableType where E: OptionalType {
func filterNil() -> Observable<E.Wrapped> {
return self.flatMap { $0.map { Observable.just($0) } ?? Observable.empty() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment