Ohm-Management - Projektarbeit B-ME
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.

partition.d.ts 2.3KB

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