@lumino/algorithm
Version:
Lumino Algorithms and Iterators
22 lines (21 loc) • 599 B
TypeScript
/**
* Filter an iterable for values which pass a test.
*
* @param object - The iterable object of interest.
*
* @param fn - The predicate function to invoke for each value.
*
* @returns An iterator which yields the values which pass the test.
*
* #### Example
* ```typescript
* import { filter } from '@lumino/algorithm';
*
* let data = [1, 2, 3, 4, 5, 6];
*
* let stream = filter(data, value => value % 2 === 0);
*
* Array.from(stream); // [2, 4, 6]
* ```
*/
export declare function filter<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): IterableIterator<T>;