@lumino/algorithm
Version:
Lumino Algorithms and Iterators
117 lines (116 loc) • 2.96 kB
TypeScript
/**
* Create an array from an iterable of values.
*
* @deprecated
*
* @param object - The iterable object of interest.
*
* @returns A new array of values from the given object.
*
* #### Example
* ```typescript
* import { toArray } from '@lumino/algorithm';
*
* let stream = [1, 2, 3, 4, 5, 6][Symbol.iterator]();
*
* toArray(stream); // [1, 2, 3, 4, 5, 6];
* ```
*/
export declare function toArray<T>(object: Iterable<T>): T[];
/**
* Create an object from an iterable of key/value pairs.
*
* @param object - The iterable object of interest.
*
* @returns A new object mapping keys to values.
*
* #### Example
* ```typescript
* import { toObject } from '@lumino/algorithm';
*
* let data: [string, number][] = [['one', 1], ['two', 2], ['three', 3]];
*
* toObject(data); // { one: 1, two: 2, three: 3 }
* ```
*/
export declare function toObject<T>(object: Iterable<[string, T]>): {
[key: string]: T;
};
/**
* Invoke a function for each value in an iterable.
*
* @deprecated
*
* @param object - The iterable object of interest.
*
* @param fn - The callback function to invoke for each value.
*
* #### Notes
* Iteration can be terminated early by returning `false` from the
* callback function.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { each } from '@lumino/algorithm';
*
* let data = [5, 7, 0, -2, 9];
*
* each(data, value => { console.log(value); });
* ```
*/
export declare function each<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean | void): void;
/**
* Test whether all values in an iterable satisfy a predicate.
*
* @param object - The iterable object of interest.
*
* @param fn - The predicate function to invoke for each value.
*
* @returns `true` if all values pass the test, `false` otherwise.
*
* #### Notes
* Iteration terminates on the first `false` predicate result.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { every } from '@lumino/algorithm';
*
* let data = [5, 7, 1];
*
* every(data, value => value % 2 === 0); // false
* every(data, value => value % 2 === 1); // true
* ```
*/
export declare function every<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): boolean;
/**
* Test whether any value in an iterable satisfies a predicate.
*
* @param object - The iterable object of interest.
*
* @param fn - The predicate function to invoke for each value.
*
* @returns `true` if any value passes the test, `false` otherwise.
*
* #### Notes
* Iteration terminates on the first `true` predicate result.
*
* #### Complexity
* Linear.
*
* #### Example
* ```typescript
* import { some } from '@lumino/algorithm';
*
* let data = [5, 7, 1];
*
* some(data, value => value === 7); // true
* some(data, value => value === 3); // false
* ```
*/
export declare function some<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): boolean;