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.

26 lines
882 B

5 years ago
5 years ago
5 years ago
  1. //
  2. // ignoreWhen.swift
  3. // RxSwiftExt
  4. //
  5. // Created by Florent Pillet on 14/04/16.
  6. // Copyright © 2016 RxSwift Community. All rights reserved.
  7. //
  8. import Foundation
  9. import RxSwift
  10. extension ObservableType {
  11. /**
  12. Ignores the elements of an observable sequence based on a predicate.
  13. - seealso: [filter operator on reactivex.io](http://reactivex.io/documentation/operators/filter.html)
  14. - seealso: [ignoreElements operator on reactivex.io](http://reactivex.io/documentation/operators/ignoreelements.html)
  15. - parameter predicate: A function to test each source element for a condition.
  16. - returns: An observable sequence that contains elements from the input sequence except those that satisfy the condition.
  17. */
  18. public func ignoreWhen(_ predicate: @escaping (Element) throws -> Bool) -> Observable<Element> {
  19. return self.asObservable().filter { try !predicate($0) }
  20. }
  21. }