Guest User

Untitled

a guest
Feb 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. import RxSwift
  2.  
  3. // trick to get a clean unwrap optional by creating an intermediate type
  4. protocol Optionable {
  5. associatedtype Wrapped
  6. var value: Wrapped? { get }
  7. }
  8.  
  9. extension Optional : Optionable {
  10. var value: Wrapped? { return self }
  11. }
  12.  
  13. extension ObservableType where Self.E : Optionable {
  14. func flatten() -> Observable<Self.E.Wrapped> {
  15. return filter { $0.value != nil} .map { $0.value! }
  16. }
  17. }
Add Comment
Please, Sign In to add comment