You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
937 B

5 years ago
  1. //
  2. // materialized+elements.swift
  3. // RxSwiftExt
  4. //
  5. // Created by Andy Chou on 1/5/17.
  6. // Copyright © 2017 RxSwift Community. All rights reserved.
  7. //
  8. import Foundation
  9. import RxSwift
  10. extension ObservableType where E: EventConvertible {
  11. /**
  12. Returns an observable sequence containing only next elements from its input
  13. - seealso: [materialize operator on reactivex.io](http://reactivex.io/documentation/operators/materialize-dematerialize.html)
  14. */
  15. public func elements() -> Observable<E.ElementType> {
  16. return filter { $0.event.element != nil }
  17. .map { $0.event.element! }
  18. }
  19. /**
  20. Returns an observable sequence containing only error elements from its input
  21. - seealso: [materialize operator on reactivex.io](http://reactivex.io/documentation/operators/materialize-dematerialize.html)
  22. */
  23. public func errors() -> Observable<Swift.Error> {
  24. return filter { $0.event.error != nil }
  25. .map { $0.event.error! }
  26. }
  27. }