itertools-ts
Version:
Extended itertools port for TypeScript and JavaScript. Provides a huge set of functions for working with iterable collections (including async ones)
93 lines (92 loc) • 3.58 kB
TypeScript
import { RecordKey } from "./types";
import { AsyncRelatedIterable, RelatedIterable } from "./tools";
/**
* Converts collection or record to Iterable instance.
*
* If instance is already an iterable then just return it.
*
* @param collection
*/
export declare function toIterable<T>(collection: Iterable<T> | Iterator<T> | Record<RecordKey, unknown>): Iterable<T>;
/**
* Converts collection or record to AsyncIterable instance.
*
* If instance is already an async iterable then just return it.
*
* @param collection
*/
export declare function toAsyncIterable<T>(collection: Iterable<T> | Iterator<T> | AsyncIterable<T> | AsyncIterator<T> | Record<RecordKey, unknown>): AsyncIterable<T>;
/**
* Converts collection to Iterator instance.
*
* If instance is already an iterator then just return it.
*
* @param collection
*/
export declare function toIterator<T>(collection: Iterable<T> | Iterator<T>): Iterator<T>;
/**
* Converts collection to AsyncIterator instance.
*
* @param collection
*/
export declare function toAsyncIterator<T>(collection: Iterable<T> | Iterator<T> | AsyncIterable<T> | AsyncIterator<T>): AsyncIterator<T>;
/**
* Converts given collection to array.
*
* @param collection
*/
export declare function toArray<T>(collection: Iterable<T> | Iterator<T>): Array<T>;
/**
* Converts given async collection to array.
*
* @param collection
*/
export declare function toArrayAsync<T>(collection: AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>): Promise<Array<T>>;
/**
* Converts collection of key-value pairs to Map.
*
* @param pairs
*/
export declare function toMap<TKey, TValue>(pairs: Iterable<[TKey, TValue]> | Iterator<[TKey, TValue]> | Record<RecordKey, unknown>): Map<TKey, TValue>;
/**
* Converts async collection of key-value pairs to Map.
*
* @param pairs
*/
export declare function toMapAsync<TKey, TValue>(pairs: AsyncIterable<[TKey, TValue]> | AsyncIterator<[TKey, TValue]> | Iterable<[TKey, TValue]> | Iterator<[TKey, TValue]> | Record<RecordKey, unknown>): Promise<Map<TKey, TValue>>;
/**
* Converts given collection to Set.
*
* @param collection
*/
export declare function toSet<T>(collection: Iterable<T> | Iterator<T>): Set<T>;
/**
* Converts given async collection to Set.
*
* @param collection
*/
export declare function toSetAsync<T>(collection: AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>): Promise<Set<T>>;
/**
* Return several independent (duplicated) iterables from a single iterable.
*
* Once tee has been called to duplicate iterators, it is advisable to not use the original input iterator any further.
*
* Duplicating iterators can use up memory. Consider if tee is the right solution. For example, arrays and most
* iterators can be rewound and reiterated without need for duplication.
*
* @param collection
* @param count
*/
export declare function tee<T>(collection: Iterable<T> | Iterator<T>, count: number): Array<RelatedIterable<T>>;
/**
* Return several independent (duplicated) async iterables from a single async iterable.
*
* Once tee has been called to duplicate iterators, it is advisable to not use the original input iterator any further.
*
* Duplicating iterators can use up memory. Consider if tee is the right solution. For example, arrays and most
* iterators can be rewound and reiterated without need for duplication.
*
* @param collection
* @param count
*/
export declare function teeAsync<T>(collection: AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>, count: number): Array<AsyncRelatedIterable<T>>;