@js-data-tools/js-helpers
Version:
A set of JavaScript / TypeScript helper functions for parsing, converting, transforming and formatting data.
143 lines (142 loc) • 8.26 kB
TypeScript
/**
* Filter elements of the iterable collection, using the given predicate function.
*
* @description This function does not iterate the source collection by itself, it just creates a wrapper iterable object.
* When the caller enumerates entries of that wrapper object, the implementation delegates the call to the internal (source)
* iterator, skipping values that do not pass the given filter.
*
* @since 0.1.2
* @category iterable
* @param from - The enumerable collection to filter elements of.
* @param predicate - The predicate function, receiving a single collection's element as a parameter and returning true to keep that element (or false to skip it)
* @returns A new iterable object, which, when iterated, will return elements from the inner collection, filtered with the given predicate (e.g. only
* those that the predicate returns true for them)
*/
export declare function filter<T>(from: Iterable<T> | undefined | null, predicate?: ((item: T) => boolean) | null): Generator<T, void, undefined>;
/**
* Take (up to) first N elements of the given iterable collection.
*
* @description This function does not iterate the source collection by itself, it just creates a wrapper iterable object.
* When the caller enumerates entries of that wrapper object, the implementation delegates the call to the internal (source)
* iterator up to <N> times and then stops the enumeration as if the original iterator reached the end of the sequence.
*
* @since 0.1.2
* @category iterable
* @param from - The enumerable object to take elements of.
* @param {number} count - The number of elements to take. A negative count stands for "take all elements".
* @returns A new iterable object, which, when iterated, will return the first <count> elements from the source collection (or less
* is the source collection is shorter than <count>).
*/
export declare function take<T>(from: Iterable<T> | undefined | null, count: number): Generator<T, void, undefined>;
/**
* Enumerate elements of the given iterable collection, while they satisfy given condition (predicate).
*
* @description This function does not iterate the source collection by itself, it just creates a wrapper iterable object.
* When the caller enumerates entries of that wrapper object, the implementation delegates the call to the internal (source)
* iterator. It checks every element using the given predicate and stops the enumeration when predicate returns false.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to take elements of.
* @param condition The predicate, taking a collection's element as a parameter and returning false to stop enumeration.
* @returns A new enumerable objects, which will return first elements of the source collection, which all satisfy the given condition.
*/
export declare function takeWhile<T>(from: Iterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): Generator<T, void, undefined>;
/**
* Enumerate elements of the given iterable collection, until some element satisfies the given condition (predicate).
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to take elements of.
* @param condition The predicate, taking a collection's element as a parameter and returning false to stop enumeration.
*/
export declare function takeUntil<T>(from: Iterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): Generator<T, void, undefined>;
/**
* Skip (up to) first N elements of the given iterable collection.
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to skip elements of.
* @param count The number of elements to skip
*/
export declare function skip<T>(from: Iterable<T> | undefined | null, count: number): Generator<T, void, undefined>;
/**
* Skip first elements of the iterable collection, while they match a given condition.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to skip elements of.
* @param condition The predicate function, getting a collection's element and returning true if element should be skipped (false to stop skipping and return the rest)
*/
export declare function skipWhile<T>(from: Iterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): Generator<T, void, undefined>;
/**
* Skip first elements of the iterable collection until one of them matches a given condition.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to skip elements of.
* @param condition The predicate function, getting a collection's element and returning false if element should be skipped (true to stop skipping and return the rest)
*/
export declare function skipUntil<T>(from: Iterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): Generator<T, void, undefined>;
/**
* Filter elements of the given iterable collection, using given predicate function.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to filter elements of.
* @param predicate The predicate function, receiving a single collection's element as a parameter and returning true to keep that element (or false to skip it)
*/
export declare function filterAsync<T>(from: AsyncIterable<T> | undefined | null, predicate?: ((item: T) => boolean) | null): AsyncGenerator<T, void, undefined>;
/**
* Take (up to) first N elements of the given iterable collection.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to take elements of.
* @param count The number of elements to take
*/
export declare function takeAsync<T>(from: AsyncIterable<T> | undefined | null, count: number): AsyncGenerator<T, void, undefined>;
/**
* Enumerate elements of the given iterable collection, while they satisfy given condition (predicate).
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to take elements of.
* @param condition The predicate, taking a collection's element as a parameter and returning false to stop enumeration.
*/
export declare function takeWhileAsync<T>(from: AsyncIterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): AsyncGenerator<T, void, undefined>;
/**
* Enumerate elements of the given iterable collection, until some element satisfies the given condition (predicate).
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to take elements of.
* @param condition The predicate, taking a collection's element as a parameter and returning false to stop enumeration.
*/
export declare function takeUntilAsync<T>(from: AsyncIterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): AsyncGenerator<T, void, undefined>;
/**
* Skip (up to) first N elements of the given iterable collection.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to skip elements of.
* @param count The number of elements to skip
*/
export declare function skipAsync<T>(from: AsyncIterable<T> | undefined | null, count: number): AsyncGenerator<T, void, undefined>;
/**
* Skip first elements of the iterable collection, while they match a given condition.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to skip elements of.
* @param condition The predicate function, getting a collection's element and returning true if element should be skipped (false to stop skipping and return the rest)
*/
export declare function skipWhileAsync<T>(from: AsyncIterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): AsyncGenerator<T, void, undefined>;
/**
* Skip first elements of the iterable collection until one of them matches a given condition.
*
* @since 0.1.2
* @category iterable
* @param from The enumerable collection to skip elements of.
* @param condition The predicate function, getting a collection's element and returning false if element should be skipped (true to stop skipping and return the rest)
*/
export declare function skipUntilAsync<T>(from: AsyncIterable<T> | undefined | null, condition: ((item: T) => boolean) | null | undefined): AsyncGenerator<T, void, undefined>;