@softwareventures/async-iterable
Version:
Pure functional AsyncIterable traversal
208 lines (207 loc) • 20.5 kB
TypeScript
import type { Comparator } from "@softwareventures/ordered";
export type AsyncIterableLike<T> = AsyncIterable<T> | Iterable<T | Promise<T>> | Promise<AsyncIterable<T>> | Promise<Iterable<T | Promise<T>>>;
export declare function asyncIterable<T>(iterable: AsyncIterableLike<T>): AsyncIterable<T>;
export declare function asyncIterator<T>(iterable: AsyncIterableLike<T>): AsyncIterator<T>;
export declare function isAsyncIterable<T = unknown>(value: AsyncIterable<T> | unknown): value is AsyncIterable<T>;
export declare function toArray<T>(iterable: AsyncIterableLike<T>): Promise<T[]>;
export declare const asyncToArray: typeof toArray;
export declare function toSet<T>(iterable: AsyncIterableLike<T>): Promise<Set<T>>;
export declare const asyncToSet: typeof toSet;
export declare function first<T>(iterable: AsyncIterableLike<T>): Promise<T | null>;
export declare const asyncFirst: typeof first;
export declare function tail<T>(iterable: AsyncIterableLike<T>): AsyncIterable<T>;
export declare const asyncTail: typeof tail;
export declare function push<T>(iterable: AsyncIterableLike<T>, value: T | Promise<T>): AsyncIterable<T>;
export declare const asyncPush: typeof push;
export declare function pushFn<T>(value: T | Promise<T>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncPushFn: typeof pushFn;
export declare function unshift<T>(iterable: AsyncIterableLike<T>, value: T | Promise<T>): AsyncIterable<T>;
export declare const asyncUnshift: typeof unshift;
export declare function unshiftFn<T>(value: T | Promise<T>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncUnshiftFn: typeof unshiftFn;
export declare function initial<T>(iterable: AsyncIterable<T>): AsyncIterable<T>;
export declare const asyncInitial: typeof initial;
export declare function last<T>(iterable: AsyncIterableLike<T>): Promise<T | null>;
export declare const asyncLast: typeof last;
export declare function only<T>(iterable: AsyncIterableLike<T>): Promise<T | null>;
export declare const asyncOnly: typeof only;
export declare function empty(iterable: AsyncIterableLike<unknown>): Promise<boolean>;
export declare const asyncEmpty: typeof empty;
export declare function notEmpty(iterable: AsyncIterableLike<unknown>): Promise<boolean>;
export declare const asyncNotEmpty: typeof notEmpty;
export declare function slice<T>(iterable: AsyncIterableLike<T>, start?: number | Promise<number>, end?: number | Promise<number>): AsyncIterable<T>;
export declare function take<T>(iterable: AsyncIterableLike<T>, count: number | Promise<number>): AsyncIterable<T>;
export declare const asyncTake: typeof take;
export declare function takeFn<T>(count: number | Promise<number>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncTakeFn: typeof takeFn;
export declare function drop<T>(iterable: AsyncIterableLike<T>, count: number | Promise<number>): AsyncIterable<T>;
export declare const asyncDrop: typeof drop;
export declare function dropFn<T>(count: number | Promise<number>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncDropFn: typeof dropFn;
export declare function takeWhile<T, U extends T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => element is U): AsyncIterable<U>;
export declare function takeWhile<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): AsyncIterable<T>;
export declare const asyncTakeWhile: typeof takeWhile;
export declare function takeWhileFn<T, U extends T>(predicate: (element: T, index: number) => element is U): (iterable: AsyncIterableLike<T>) => AsyncIterable<U>;
export declare function takeWhileFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncTakeWhileFn: typeof takeWhileFn;
export declare function takeUntil<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): AsyncIterable<T>;
export declare const asyncTakeUntil: typeof takeUntil;
export declare function takeUntilFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncTakeUntilFn: typeof takeUntilFn;
export declare function dropWhile<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): AsyncIterable<T>;
export declare const asyncDropWhile: typeof dropWhile;
export declare function dropWhileFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare function dropUntil<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): AsyncIterable<T>;
export declare const asyncDropUntil: typeof dropUntil;
export declare function dropUntilFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncDropUntilFn: typeof dropUntilFn;
export declare function equal<T>(a: AsyncIterableLike<T>, b: AsyncIterableLike<T>, elementsEqual?: (a: T, b: T) => boolean | Promise<boolean>): Promise<boolean>;
export declare const asyncEqual: typeof equal;
export declare function equalFn<T>(b: AsyncIterableLike<T>, elementsEqual?: (a: T, b: T) => boolean | Promise<boolean>): (a: AsyncIterableLike<T>) => Promise<boolean>;
export declare const asyncEqualFn: typeof equalFn;
export declare function notEqual<T>(a: AsyncIterableLike<T>, b: AsyncIterableLike<T>, elementsEqual?: (a: T, b: T) => boolean | Promise<boolean>): Promise<boolean>;
export declare const asyncNotEqual: typeof notEqual;
export declare function notEqualFn<T>(b: AsyncIterableLike<T>, elementsEqual?: (a: T, b: T) => boolean | Promise<boolean>): (a: AsyncIterableLike<T>) => Promise<boolean>;
export declare const asyncNotEqualFn: typeof notEqualFn;
export declare function prefixMatch<T>(a: AsyncIterableLike<T>, b: AsyncIterableLike<T>, elementsEqual?: (a: T, b: T) => boolean | Promise<boolean>): Promise<boolean>;
export declare const asyncPrefixMatch: typeof prefixMatch;
export declare function prefixMatchFn<T>(b: AsyncIterableLike<T>, elementsEqual?: (a: T, b: T) => boolean | Promise<boolean>): (a: AsyncIterableLike<T>) => Promise<boolean>;
export declare const asyncPrefixMatchFn: typeof prefixMatchFn;
export declare function map<T, U>(iterable: AsyncIterableLike<T>, f: (element: T, index: number) => U | Promise<U>): AsyncIterable<U>;
export declare const asyncMap: typeof map;
export declare function mapFn<T, U>(f: (element: T) => U | Promise<U>): (iterable: AsyncIterableLike<T>) => AsyncIterable<U>;
export declare const asyncMapFn: typeof mapFn;
export declare function filter<T, U extends T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => element is U): AsyncIterable<U>;
export declare function filter<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): AsyncIterable<T>;
export declare const asyncFilter: typeof filter;
export declare function filterFn<T, U extends T>(predicate: (element: T, index: number) => element is U): (iterable: AsyncIterableLike<T>) => AsyncIterable<U>;
export declare function filterFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncFilterFn: typeof filterFn;
export declare function exclude<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): AsyncIterable<T>;
export declare const asyncExclude: typeof exclude;
export declare function excludeFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncExcludeFn: typeof exclude;
export declare function excludeNull<T>(iterable: AsyncIterableLike<T | null | undefined>): AsyncIterable<T>;
export declare const asyncExcludeNull: typeof excludeNull;
export declare function excludeFirst<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): AsyncIterable<T>;
export declare const asyncExcludeFirst: typeof excludeFirst;
export declare function excludeFirstFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncExcludeFirstFn: typeof excludeFirstFn;
export declare function remove<T>(iterable: AsyncIterableLike<T>, value: T): AsyncIterable<T>;
export declare const asyncRemove: typeof remove;
export declare function removeFn<T>(value: T): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncRemoveFn: typeof removeFn;
export declare function removeFirst<T>(iterable: AsyncIterableLike<T>, value: T): AsyncIterable<T>;
export declare const asyncRemoveFirst: typeof removeFirst;
export declare function removeFirstFn<T>(value: T): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncRemoveFirstFn: typeof removeFirstFn;
export declare function fold<T, U>(iterable: AsyncIterableLike<T>, f: (accumulator: U, element: T, index: number) => U | Promise<U>, initial: U): Promise<U>;
export declare const asyncFold: typeof fold;
export declare function foldFn<T, U>(f: (accumulator: U, element: T, index: number) => U | Promise<U>, initial: U): (iterable: AsyncIterableLike<T>) => Promise<U>;
export declare const asyncFoldFn: typeof foldFn;
export declare function fold1<T>(iterable: AsyncIterableLike<T>, f: (accumulator: T, element: T, index: number) => T | Promise<T>): Promise<T>;
export declare const asyncFold1: typeof fold1;
export declare function fold1Fn<T>(f: (accumulator: T, element: T, index: number) => T | Promise<T>): (iterable: AsyncIterableLike<T>) => Promise<T>;
export declare const asyncFold1Fn: typeof fold1Fn;
export declare function index<T>(iterable: AsyncIterableLike<T>, index: number): Promise<T | null>;
export declare const asyncIndex: typeof index;
export declare function indexFn<T>(index: number): (iterable: AsyncIterableLike<T>) => Promise<T | null>;
export declare const asyncIndexFn: typeof indexFn;
export declare function contains<T>(iterable: AsyncIterableLike<T>, value: T): Promise<boolean>;
export declare const asyncContains: typeof contains;
export declare function containsFn<T>(value: T): (iterable: AsyncIterableLike<T>) => Promise<boolean>;
export declare const asyncContainsFn: typeof containsFn;
export declare function indexOf<T>(iterable: AsyncIterableLike<T>, value: T): Promise<number | null>;
export declare const asyncIndexOf: typeof indexOf;
export declare function indexOfFn<T>(value: T): (iterable: AsyncIterableLike<T>) => Promise<number | null>;
export declare const asyncIndexOfFn: typeof indexOfFn;
export declare function findIndex<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): Promise<number | null>;
export declare const asyncFindIndex: typeof findIndex;
export declare function findIndexFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => Promise<number | null>;
export declare const asyncFindIndexFn: typeof findIndexFn;
export declare function find<T, U extends T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => element is U): Promise<U | null>;
export declare function find<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): Promise<T | null>;
export declare const asyncFind: typeof find;
export declare function findFn<T, U extends T>(predicate: (element: T, index: number) => element is U): (iterable: AsyncIterableLike<T>) => Promise<U | null>;
export declare function findFn<T>(predicate: (element: T, index: number) => boolean | Promise<boolean>): (iterable: AsyncIterableLike<T>) => Promise<T | null>;
export declare const asyncFindFn: typeof findFn;
export declare function maximum<T extends string | number | boolean>(iterable: AsyncIterableLike<T>): Promise<T | null>;
export declare function maximum<T>(iterable: AsyncIterableLike<T>, compare: Comparator<T>): Promise<T | null>;
export declare const asyncMaximum: typeof maximum;
export declare function maximumFn<T>(compare: Comparator<T>): (iterable: AsyncIterableLike<T>) => Promise<T | null>;
export declare const asyncMaximumFn: typeof maximumFn;
export declare function maximumBy<T>(iterable: AsyncIterableLike<T>, select: (element: T, index: number) => number | Promise<number>): Promise<T | null>;
export declare const asyncMaximumBy: typeof maximumBy;
export declare function maximumByFn<T>(select: (element: T, index: number) => number | Promise<number>): (iterable: AsyncIterableLike<T>) => Promise<T | null>;
export declare const asyncMaximumByFn: typeof maximumByFn;
export declare function minimum<T extends string | number | boolean>(iterable: AsyncIterableLike<T>): Promise<T | null>;
export declare function minimum<T>(iterable: AsyncIterableLike<T>, compare: Comparator<T>): Promise<T | null>;
export declare const asyncMinimum: typeof minimum;
export declare function minimumFn<T>(compare: Comparator<T>): (iterable: AsyncIterableLike<T>) => Promise<T | null>;
export declare const asyncMinimumFn: typeof minimumFn;
export declare function minimumBy<T>(iterable: AsyncIterableLike<T>, select: (element: T, index: number) => number | Promise<number>): Promise<T | null>;
export declare const asyncMinimumBy: typeof minimumBy;
export declare function minimumByFn<T>(select: (element: T, index: number) => number | Promise<number>): (iterable: AsyncIterableLike<T>) => Promise<T | null>;
export declare const asyncMinimumByFn: typeof minimumByFn;
export declare function sum(iterable: AsyncIterableLike<number>): Promise<number>;
export declare const asyncSum: typeof sum;
export declare function product(iterable: AsyncIterableLike<number>): Promise<number>;
export declare const asyncProduct: typeof product;
export declare function average(iterable: AsyncIterableLike<number>): Promise<number | null>;
export declare const asyncAverage: typeof average;
export declare function and(iterable: AsyncIterableLike<boolean>): Promise<boolean>;
export declare const asyncAnd: typeof and;
export declare function or(iterable: AsyncIterableLike<boolean>): Promise<boolean>;
export declare const asyncOr: typeof or;
export declare function any<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): Promise<boolean>;
export declare const asyncAny: typeof any;
export declare function all<T>(iterable: AsyncIterableLike<T>, predicate: (element: T, index: number) => boolean | Promise<boolean>): Promise<boolean>;
export declare const asyncAll: typeof all;
export declare function concat<T>(iterables: AsyncIterableLike<AsyncIterableLike<T>>): AsyncIterable<T>;
export declare const asyncConcat: typeof concat;
export declare function prepend<T>(a: AsyncIterableLike<T>): (b: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncPrepend: typeof prepend;
export declare function append<T>(b: AsyncIterableLike<T>): (a: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare const asyncAppend: typeof append;
export declare function concatMap<T, U>(iterable: AsyncIterableLike<T>, f: (element: T, index: number) => AsyncIterableLike<U>): AsyncIterable<U>;
export declare const asyncConcatMap: typeof concatMap;
export declare function concatMapFn<T, U>(f: (element: T, index: number) => AsyncIterableLike<U>): (iterable: AsyncIterableLike<T>) => AsyncIterable<U>;
export declare const asyncConcatMapFn: typeof concatMapFn;
export declare function noneNull<T>(iterable: AsyncIterableLike<T | null | undefined>): Promise<T[] | null>;
export declare const asyncNoneNull: typeof noneNull;
export declare function scan<T, U>(iterable: AsyncIterableLike<T>, f: (accumulator: U, element: T, index: number) => U | Promise<U>, initial: U): AsyncIterable<U>;
export declare const asyncScan: typeof scan;
export declare function scanFn<T, U>(f: (accumulator: U, element: T, index: number) => U | Promise<U>, initial: U): (iterable: AsyncIterableLike<T>) => AsyncIterable<U>;
export declare const asyncScanFn: typeof scanFn;
export declare function scan1<T>(iterable: AsyncIterableLike<T>, f: (accumulator: T, element: T, index: number) => T | Promise<T>): AsyncIterable<T>;
export declare const asyncScan1: typeof scan1;
export declare function scan1Fn<T>(f: (accumulator: T, element: T, index: number) => T | Promise<T>): (iterable: AsyncIterableLike<T>) => AsyncIterable<T>;
export declare function pairwise<T>(iterable: AsyncIterableLike<T>): AsyncIterable<readonly [T, T]>;
export declare function zip<T, U>(a: AsyncIterableLike<T>, b: AsyncIterableLike<U>): AsyncIterable<readonly [T, U]>;
export declare const asyncZip: typeof zip;
export declare function zipFn<T, U>(b: AsyncIterableLike<U>): (a: AsyncIterableLike<T>) => AsyncIterable<readonly [T, U]>;
export declare const asyncZipFn: typeof zipFn;
export declare function keyBy<TKey, TElement>(iterable: AsyncIterableLike<TElement>, f: (element: TElement, index: number) => TKey): Promise<Map<TKey, TElement[]>>;
export declare const asyncKeyBy: typeof keyBy;
export declare function keyByFn<TKey, TElement>(f: (element: TElement, index: number) => TKey): (iterable: AsyncIterableLike<TElement>) => Promise<Map<TKey, TElement[]>>;
export declare const asyncKeyByFn: typeof keyByFn;
export declare function keyFirstBy<TKey, TElement>(iterable: AsyncIterableLike<TElement>, f: (element: TElement, index: number) => TKey): Promise<Map<TKey, TElement>>;
export declare const asyncKeyFirstBy: typeof keyFirstBy;
export declare function keyFirstByFn<TKey, TElement>(f: (element: TElement, index: number) => TKey): (iterable: AsyncIterableLike<TElement>) => Promise<Map<TKey, TElement>>;
export declare const asyncKeyFirstByFn: typeof keyFirstByFn;
export declare function keyLastBy<TKey, TElement>(iterable: AsyncIterableLike<TElement>, f: (element: TElement, index: number) => TKey): Promise<Map<TKey, TElement>>;
export declare const asyncKeyLastBy: typeof keyLastBy;
export declare function keyLastByFn<TKey, TElement>(f: (element: TElement, index: number) => TKey): (iterable: AsyncIterableLike<TElement>) => Promise<Map<TKey, TElement>>;
export declare const asyncKeyLastByFn: typeof keyLastByFn;
export declare function mapKeyBy<TKey, TElement, TNewElement>(iterable: AsyncIterableLike<TElement>, f: (element: TElement, index: number) => readonly [TKey, TNewElement] | Promise<readonly [TKey, TNewElement]>): Promise<Map<TKey, TNewElement[]>>;
export declare const asyncMapKeyBy: typeof mapKeyBy;
export declare function mapKeyByFn<TKey, TElement, TNewElement>(f: (element: TElement, index: number) => readonly [TKey, TNewElement] | Promise<readonly [TKey, TNewElement]>): (iterable: AsyncIterableLike<TElement>) => Promise<Map<TKey, TNewElement[]>>;
export declare const asyncMapKeyByFn: typeof mapKeyByFn;
export declare function mapKeyFirstBy<TKey, TElement, TNewElement>(iterable: AsyncIterableLike<TElement>, f: (element: TElement, index: number) => readonly [TKey, TNewElement] | Promise<readonly [TKey, TNewElement]>): Promise<Map<TKey, TNewElement>>;
export declare const asyncMapKeyFirstBy: typeof mapKeyFirstBy;
export declare function mapKeyFirstByFn<TKey, TElement, TNewElement>(f: (element: TElement, index: number) => readonly [TKey, TNewElement] | Promise<readonly [TKey, TNewElement]>): (iterable: AsyncIterableLike<TElement>) => Promise<Map<TKey, TNewElement>>;
export declare const asyncMapKeyFirstByFn: typeof mapKeyFirstByFn;
export declare function mapKeyLastBy<TKey, TElement, TNewElement>(iterable: AsyncIterableLike<TElement>, f: (element: TElement, index: number) => readonly [TKey, TNewElement] | Promise<readonly [TKey, TNewElement]>): Promise<Map<TKey, TNewElement>>;
export declare const asyncMapKeyLastBy: typeof mapKeyLastBy;
export declare function mapKeyLastByFn<TKey, TElement, TNewElement>(f: (element: TElement, index: number) => readonly [TKey, TNewElement] | Promise<readonly [TKey, TNewElement]>): (iterable: AsyncIterableLike<TElement>) => Promise<Map<TKey, TNewElement>>;
export declare const asyncMapKeyLastByFn: typeof mapKeyLastByFn;