Skip to content

Instantly share code, notes, and snippets.

@sergdort
Created June 2, 2017 21:20
Show Gist options
  • Save sergdort/73547627011bf1e46e04bc9a347e9ac2 to your computer and use it in GitHub Desktop.
Save sergdort/73547627011bf1e46e04bc9a347e9ac2 to your computer and use it in GitHub Desktop.
extension ObservableType {
public func map<U>(_ transform: @escaping (E) throws -> U) -> Observable<U> {
return Observable<U> { observer in
return self.subscribe(observer: Observer { (event) in
switch event {
case .next(let element):
do {
try observer.on(event: .next(transform(element)))
} catch {
observer.on(event: .error(error))
}
case .error(let e):
observer.on(event: .error(e))
case .completed:
observer.on(event: .completed)
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment