@codibre/fluent-iterable
Version:
Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).
155 lines (154 loc) • 5.96 kB
TypeScript
import { FluentAsyncIterable, FluentGroup, FluentIterable } from '../types';
import { Group, AverageStepper } from '../types/base';
import { AnyIterable, AsyncPredicate } from 'augmentative-iterable';
/**
* Returns exactly the informed parameter
* @param param The informed parameter to be returned
*/
declare function identity<T>(param: T): T;
export declare function isPromise(t: unknown): t is PromiseLike<any>;
/**
* Iterates all element of an async iterable
* @typeparam T the item type of the [[Iterable]]
* @param a The async iterable
*/
declare function iterateAsync<T>(a: AnyIterable<T> | PromiseLike<AnyIterable<T>>): AsyncIterable<T>;
/**
* Iterates in all elements of an async iterable of iterables or async iterables
* @typeparam T the item type of the internal [[Iterable/AsyncIterable]]
* @param a The async iterable
*/
declare function iterateAllAsync<T>(a: AsyncIterable<AnyIterable<T>>): AsyncGenerator<Awaited<T>, void, any>;
/**
* Iterates all element of an iterable
* @typeparam T the item type of the [[Iterable]]
* @param a The iterable
*/
declare const iterate: <T>(a: Iterable<T>) => Iterable<T>;
/**
* Returns a function that always returns the informed value
* @param value the constant value
*/
declare function constant<T>(value: T): () => T;
/**
* Iterates in all elements of an iterable of iterables
* @typeparam T the item type of the internal [[Iterable]]
* @param a The iterable
*/
declare function iterateAll<T>(a: Iterable<Iterable<T>>): Generator<T, void, any>;
/**
* Iterates over all owned properties of the given object
* @param obj The object to iterate with
*/
declare function iterateObjProps<T extends object>(obj: T): Iterable<keyof T>;
/**
* Iterates over all owned entries of given object
* @param obj The object to iterate with
*/
declare function iterateObjEntries<T extends object, K extends keyof T = keyof T, V extends T[K] = T[K]>(obj: T): Iterable<[K, V]>;
/**
* Provides a "equals" comparer
* @typeparam T the type of b
* @param b the value for comparison
*/
declare function eq<T>(b: any): (a: T) => boolean;
/**
* Provides a "greater than" comparer
* @typeparam T the type of b
* @param b the value for comparison
*/
declare function gt<T>(b: any): (a: T) => boolean;
/**
* Provides a "greater or equal" comparer
* @typeparam T the type of b
* @param b the value for comparison
*/
declare function ge<T>(b: any): (a: T) => boolean;
/**
* Provides a "lesser than" comparer
* @typeparam T the type of b
* @param b the value for comparison
*/
declare function lt<T>(b: any): (a: T) => boolean;
/**
* Provides a "lesser or equal" comparer
* @typeparam T the type of b
* @param b the value for comparison
*/
declare function le<T>(b: any): (a: T) => boolean;
/**
* Provides an empty iterable
*/
declare function empty(): Iterable<undefined>;
/**
* Provides an empty async iterable
*/
declare function emptyAsync(): AsyncIterable<undefined>;
/**
* Always returns true
*/
declare function truth(): boolean;
/**
* Always returns false
*/
declare function falsity(): boolean;
/**
* Provides a function that negates the informed predicate
* @typeparam T the item type of the [[Predicate]]
* @param predicate The predicate to be negated
*/
declare function negation<TArgs extends any[], R>(this: unknown, predicate: (...args: TArgs) => R): (...args: TArgs) => boolean;
/**
* Provides a function that negates the informed async predicate
* @typeparam T the item type of the [[AsyncPredicate]]
* @param predicate The async predicate to be negated
*/
declare function asyncNegation<T>(predicate: AsyncPredicate<T>): AsyncPredicate<T>;
/**
* Convert a simple [[Group]] to a [[FluentGroup]]
* @typeparam Key The type of the key
* @typeparam Value the type of the items of the value property
* @param {Group} grp the [[Group]] to be converted
*/
declare function fluentGroup<Key, Value>(grp: Group<Value, Key>): FluentGroup<Value, Key>;
/**
* Returns an object to calculates incremental average/iterative means
*/
declare function getAverageStepper(): AverageStepper;
/**
* Returns a new instance of a function with a order assuring mark.
* Fluent Iterable will treat order Assuring marked function as if
* they're guaranteed to return ordered result in regard some iterable
* where they're applied. The actual order, though, is of responsibility
* of the code using this package.
*
* This is useful to have access to faster versions of some algorithms, but
* the output may not match expectation if the resulting order is not actually right.
*
* @param f the function to assure order
*/
declare function assureOrder<F extends Function | AnyIterable<any>>(f: F): F;
/**
* Returns a new instance of a function with a descending order assuring mark.
* Fluent Iterable will treat descending order assuring marked functions as if
* they're guaranteed to return descending ordered results in regard some iterable
* where they're applied. The actual order, though, is of responsibility
* of the code using this package.
*
* This is useful to have access to faster versions of some algorithms, but
* the output may not match expectation if the resulting order is not actually right.
*
* @param f the function to assure order
*/
declare function assureOrderDescending<F extends Function | FluentIterable<any> | FluentAsyncIterable<any>>(f: F): F;
/**
* Mark a field name or a mapper as ascending, for use with sortBy
* @param f the mapper or the field name
*/
export declare function asc<F>(f: F): F;
/**
* Mark a field name or a mapper as descending, for use with sortBy
* @param f the mapper or the field name
*/
export declare function desc<F>(f: F): F;
export { assureOrder, assureOrderDescending, constant, empty, emptyAsync, identity, truth, falsity, negation, asyncNegation, fluentGroup, getAverageStepper, eq, ge, gt, le, lt, iterateAsync, iterateAllAsync, iterate, iterateAll, iterateObjProps, iterateObjEntries, };