UNPKG

itertools-ts

Version:

Extended itertools port for TypeScript and JavaScript. Provides a huge set of functions for working with iterable collections (including async ones)

204 lines (203 loc) 6.99 kB
import { Comparable } from "./types"; /** * Returns true if all elements match the predicate function. * * Empty collections return true. * * @param data * @param predicate */ export declare function allMatch<T>(data: Iterable<T> | Iterator<T>, predicate: (item: T) => boolean): boolean; /** * Returns true if all elements of async collection match the predicate function. * * Empty collections return true. * * @param data * @param predicate */ export declare function allMatchAsync<T>(data: AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>, predicate: (item: T) => Promise<boolean> | boolean): Promise<boolean>; /** * Return true if all elements in given collection are unique. * * Empty collections return true. * * Considers different instances of data containers to be different, even if they have the same content. * * @param data */ export declare function allUnique(data: Iterable<unknown> | Iterator<unknown>): boolean; /** * Return true if all elements in given async collection are unique. * * Empty collections return true. * * Considers different instances of data containers to be different, even if they have the same content. * * @param data */ export declare function allUniqueAsync(data: AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>): Promise<boolean>; /** * Returns true if any element matches the predicate function. * * Empty collections return false. * * @param data * @param predicate */ export declare function anyMatch<T>(data: Iterable<T> | Iterator<T>, predicate: (item: T) => boolean): boolean; /** * Returns true if any element of async collection matches the predicate function. * * Empty collections return false. * * @param data * @param predicate */ export declare function anyMatchAsync<T>(data: AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>, predicate: (item: T) => Promise<boolean> | boolean): Promise<boolean>; /** * Returns true if exactly n items in the iterable are true where the predicate function is true. * * Default predicate if not provided is the boolean value of each data item. * * @param data * @param n * @param predicate */ export declare function exactlyN<T>(data: Iterable<T> | Iterator<T>, n: number, predicate?: (item: T) => boolean): boolean; /** * Returns true if exactly n items in the async iterable are true where the predicate function is true. * * Default predicate if not provided is the boolean value of each data item. * * @param data * @param n * @param predicate */ export declare function exactlyNAsync<T>(data: AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>, n: number, predicate?: (item: T) => Promise<boolean> | boolean): Promise<boolean>; /** * Returns true if given collection is empty. * * @param data */ export declare function isEmpty(data: Iterable<unknown> | Iterator<unknown>): boolean; /** * Returns true if given async collection is empty. * * @param data */ export declare function isEmptyAsync(data: AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>): Promise<boolean>; /** * Return true if given input is an Iterable instance. * * @param input */ export declare function isIterable(input: unknown): boolean; /** * Return true if given input is an AsyncIterable instance. * * @param input */ export declare function isAsyncIterable(input: unknown): boolean; /** * Return true if given input is an Iterator instance. * * @param input */ export declare function isIterator(input: unknown): boolean; /** * Returns true if given collection is sorted in descending order; otherwise false. * * Items of given collection must be comparable. * * Returns true if given collection is empty or has only one element. * * @param data */ export declare function isReversed(data: Iterable<Comparable> | Iterator<Comparable>): boolean; /** * Returns true if given async collection is sorted in descending order; otherwise false. * * Items of given collection must be comparable. * * Returns true if given collection is empty or has only one element. * * @param data */ export declare function isReversedAsync(data: AsyncIterable<Comparable> | AsyncIterator<Comparable> | Iterable<Comparable> | Iterator<Comparable>): Promise<boolean>; /** * Returns true if given collection is sorted in ascending order; otherwise false. * * Items of given collection must be comparable. * * Returns true if given collection is empty or has only one element. * * @param data */ export declare function isSorted(data: Iterable<Comparable> | Iterator<Comparable>): boolean; /** * Returns true if given async collection is sorted in ascending order; otherwise false. * * Items of given collection must be comparable. * * Returns true if given collection is empty or has only one element. * * @param data */ export declare function isSortedAsync(data: AsyncIterable<Comparable> | AsyncIterator<Comparable> | Iterable<Comparable> | Iterator<Comparable>): Promise<boolean>; /** * Return true if given input is string. * * @param input */ export declare function isString(input: unknown): boolean; /** * Returns true if no element matches the predicate function. * * Empty collections return true. * * @param data * @param predicate */ export declare function noneMatch<T>(data: Iterable<T> | Iterator<T>, predicate: (item: T) => boolean): boolean; /** * Returns true if no element in async collection matches the predicate function. * * Empty collections return true. * * @param data * @param predicate */ export declare function noneMatchAsync<T>(data: AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>, predicate: (item: T) => Promise<boolean> | boolean): Promise<boolean>; /** * Returns true if all given collections are the same. * * For single collection or empty collections list returns true. * * @param collections */ export declare function same(...collections: Array<Iterable<unknown> | Iterator<unknown>>): boolean; /** * Returns true if all given async collections are the same. * * For single collection or empty collections list returns true. * * @param collections */ export declare function sameAsync(...collections: Array<AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>>): Promise<boolean>; /** * Returns true if all given collections have the same lengths. * * For single collection or empty collections list returns true. * * @param collections */ export declare function sameCount(...collections: Array<Iterable<unknown> | Iterator<unknown>>): boolean; /** * Returns true if all given async collections have the same lengths. * * For single collection or empty collections list returns true. * * @param collections */ export declare function sameCountAsync(...collections: Array<AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>>): Promise<boolean>;