f7a3d65a5b2665b808e72f44adb3266ede66a99beef8c5fcfabf8ec42c48e22a58c3412f88c4e1eaeef089e06063334819669b58cb9291614a77f7194ffe42 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Observable } from '../Observable';
  2. import { UnaryFunction } from '../types';
  3. /**
  4. * Splits the source Observable into two, one with values that satisfy a
  5. * predicate, and another with values that don't satisfy the predicate.
  6. *
  7. * <span class="informal">It's like {@link filter}, but returns two Observables:
  8. * one like the output of {@link filter}, and the other with values that did not
  9. * pass the condition.</span>
  10. *
  11. * ![](partition.png)
  12. *
  13. * `partition` outputs an array with two Observables that partition the values
  14. * from the source Observable through the given `predicate` function. The first
  15. * Observable in that array emits source values for which the predicate argument
  16. * returns true. The second Observable emits source values for which the
  17. * predicate returns false. The first behaves like {@link filter} and the second
  18. * behaves like {@link filter} with the predicate negated.
  19. *
  20. * ## Example
  21. *
  22. * Partition click events into those on DIV elements and those elsewhere
  23. *
  24. * ```ts
  25. * import { fromEvent } from 'rxjs';
  26. * import { partition } from 'rxjs/operators';
  27. *
  28. * const div = document.createElement('div');
  29. * div.style.cssText = 'width: 200px; height: 200px; background: #09c;';
  30. * document.body.appendChild(div);
  31. *
  32. * const clicks = fromEvent(document, 'click');
  33. * const [clicksOnDivs, clicksElsewhere] = clicks.pipe(partition(ev => (<HTMLElement>ev.target).tagName === 'DIV'));
  34. *
  35. * clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x));
  36. * clicksElsewhere.subscribe(x => console.log('Other clicked: ', x));
  37. * ```
  38. *
  39. * @see {@link filter}
  40. *
  41. * @param predicate A function that evaluates each value emitted by the source
  42. * Observable. If it returns `true`, the value is emitted on the first Observable
  43. * in the returned array, if `false` the value is emitted on the second Observable
  44. * in the array. The `index` parameter is the number `i` for the i-th source
  45. * emission that has happened since the subscription, starting from the number `0`.
  46. * @param thisArg An optional argument to determine the value of `this` in the
  47. * `predicate` function.
  48. * @return A function that returns an array with two Observables: one with
  49. * values that passed the predicate, and another with values that did not pass
  50. * the predicate.
  51. * @deprecated Replaced with the {@link partition} static creation function. Will be removed in v8.
  52. */
  53. export declare function partition<T>(predicate: (value: T, index: number) => boolean, thisArg?: any): UnaryFunction<Observable<T>, [Observable<T>, Observable<T>]>;
  54. //# sourceMappingURL=partition.d.ts.map