123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. var partition_1 = require('../operators/partition');
  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. * <img src="./img/partition.png" width="100%">
  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 <caption>Partition click events into those on DIV elements and those elsewhere</caption>
  21. * var clicks = Rx.Observable.fromEvent(document, 'click');
  22. * var parts = clicks.partition(ev => ev.target.tagName === 'DIV');
  23. * var clicksOnDivs = parts[0];
  24. * var clicksElsewhere = parts[1];
  25. * clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x));
  26. * clicksElsewhere.subscribe(x => console.log('Other clicked: ', x));
  27. *
  28. * @see {@link filter}
  29. *
  30. * @param {function(value: T, index: number): boolean} predicate A function that
  31. * evaluates each value emitted by the source Observable. If it returns `true`,
  32. * the value is emitted on the first Observable in the returned array, if
  33. * `false` the value is emitted on the second Observable in the array. The
  34. * `index` parameter is the number `i` for the i-th source emission that has
  35. * happened since the subscription, starting from the number `0`.
  36. * @param {any} [thisArg] An optional argument to determine the value of `this`
  37. * in the `predicate` function.
  38. * @return {[Observable<T>, Observable<T>]} An array with two Observables: one
  39. * with values that passed the predicate, and another with values that did not
  40. * pass the predicate.
  41. * @method partition
  42. * @owner Observable
  43. */
  44. function partition(predicate, thisArg) {
  45. return partition_1.partition(predicate, thisArg)(this);
  46. }
  47. exports.partition = partition;
  48. //# sourceMappingURL=partition.js.map