1 | import { IIterator, IterableOrArrayLike } from './iter';
|
2 | /**
|
3 | * Filter an iterable for values which pass a test.
|
4 | *
|
5 | * @param object - The iterable or array-like object of interest.
|
6 | *
|
7 | * @param fn - The predicate function to invoke for each value.
|
8 | *
|
9 | * @returns An iterator which yields the values which pass the test.
|
10 | *
|
11 | * #### Example
|
12 | * ```typescript
|
13 | * import { filter, toArray } from '@phosphor/algorithm';
|
14 | *
|
15 | * let data = [1, 2, 3, 4, 5, 6];
|
16 | *
|
17 | * let stream = filter(data, value => value % 2 === 0);
|
18 | *
|
19 | * toArray(stream); // [2, 4, 6]
|
20 | * ```
|
21 | */
|
22 | export declare function filter<T>(object: IterableOrArrayLike<T>, fn: (value: T, index: number) => boolean): IIterator<T>;
|
23 | /**
|
24 | * An iterator which yields values which pass a test.
|
25 | */
|
26 | export declare class FilterIterator<T> implements IIterator<T> {
|
27 | /**
|
28 | * Construct a new filter iterator.
|
29 | *
|
30 | * @param source - The iterator of values of interest.
|
31 | *
|
32 | * @param fn - The predicate function to invoke for each value.
|
33 | */
|
34 | constructor(source: IIterator<T>, fn: (value: T, index: number) => boolean);
|
35 | /**
|
36 | * Get an iterator over the object's values.
|
37 | *
|
38 | * @returns An iterator which yields the object's values.
|
39 | */
|
40 | iter(): IIterator<T>;
|
41 | /**
|
42 | * Create an independent clone of the iterator.
|
43 | *
|
44 | * @returns A new independent clone of the iterator.
|
45 | */
|
46 | clone(): IIterator<T>;
|
47 | /**
|
48 | * Get the next value from the iterator.
|
49 | *
|
50 | * @returns The next value from the iterator, or `undefined`.
|
51 | */
|
52 | next(): T | undefined;
|
53 | private _index;
|
54 | private _source;
|
55 | private _fn;
|
56 | }
|