source: trip-planner-front/node_modules/rxjs/internal/observable/partition.d.ts@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1import { ObservableInput } from '../types';
2import { Observable } from '../Observable';
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 a set of numbers into odds and evens observables
22 * ```ts
23 * import { of, partition } from 'rxjs';
24 *
25 * const observableValues = of(1, 2, 3, 4, 5, 6);
26 * const [evens$, odds$] = partition(observableValues, (value, index) => value % 2 === 0);
27 *
28 * odds$.subscribe(x => console.log('odds', x));
29 * evens$.subscribe(x => console.log('evens', x));
30 *
31 * // Logs:
32 * // odds 1
33 * // odds 3
34 * // odds 5
35 * // evens 2
36 * // evens 4
37 * // evens 6
38 * ```
39 *
40 * @see {@link filter}
41 *
42 * @param {function(value: T, index: number): boolean} predicate A function that
43 * evaluates each value emitted by the source Observable. If it returns `true`,
44 * the value is emitted on the first Observable in the returned array, if
45 * `false` the value is emitted on the second Observable in the array. The
46 * `index` parameter is the number `i` for the i-th source emission that has
47 * happened since the subscription, starting from the number `0`.
48 * @param {any} [thisArg] An optional argument to determine the value of `this`
49 * in the `predicate` function.
50 * @return {[Observable<T>, Observable<T>]} An array with two Observables: one
51 * with values that passed the predicate, and another with values that did not
52 * pass the predicate.
53 */
54export declare function partition<T>(source: ObservableInput<T>, predicate: (value: T, index: number) => boolean, thisArg?: any): [Observable<T>, Observable<T>];
Note: See TracBrowser for help on using the repository browser.