39 lines
2.6 KiB
TypeScript
39 lines
2.6 KiB
TypeScript
import { AsyncSequence } from "./async/types.js";
|
|
import { Sequence } from "./sync/types.js";
|
|
|
|
export type Predicate<T> = (obj: T) => boolean;
|
|
export type AnyPredicate<T> = (obj: T) => unknown;
|
|
export type FilterPredicate<TElement, TFiltered extends TElement> = (obj: TElement) => obj is TFiltered;
|
|
export type Converter<TFrom, TTo> = (obj: TFrom) => TTo;
|
|
export type BiConverter<TFromFirst, TFromSecond, TTo> = (first: TFromFirst, second: TFromSecond) => TTo;
|
|
export type Action<T> = (obj: T) => unknown;
|
|
export type Accumulator<TElement, TAccumulator> = (acc: TAccumulator, obj: TElement) => TAccumulator;
|
|
export type Comparer<T> = (first: T, second: T) => number;
|
|
export type Equater<T> = (first: T, second: T) => boolean;
|
|
|
|
export type MaybeAsyncIterable<T> = Iterable<T> | AsyncIterable<T>;
|
|
export type MaybeAsyncIterator<T> = Iterator<T> | AsyncIterator<T>;
|
|
export type MaybeAsyncGenerator<T> = Generator<T> | AsyncGenerator<T>;
|
|
export type AsyncFunction<TFunc extends (...args: any) => any> = TFunc extends (...args: infer P) => infer R ? (...args: P) => Promise<Awaited<R>> : never;
|
|
export type MaybePromise<T> = T | Promise<T>;
|
|
export type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
export type MaybeAsyncFunction<TFunc extends (...args: any) => any> = TFunc extends (...args: infer P) => infer R ? (...args: P) => MaybePromise<R> : never;
|
|
export type MaybeAsyncSequence<T> = Sequence<T> | AsyncSequence<T>;
|
|
|
|
export type AsyncPredicate<T> = AsyncFunction<Predicate<T>>;
|
|
export type AsyncAnyPredicate<T> = AsyncFunction<AnyPredicate<T>>;
|
|
export type MaybeAsyncPredicate<T> = MaybeAsyncFunction<Predicate<T>>;
|
|
export type MaybeAsyncAnyPredicate<T> = MaybeAsyncFunction<AnyPredicate<T>>;
|
|
export type AsyncConverter<TFrom, TTo> = AsyncFunction<Converter<TFrom, TTo>>;
|
|
export type MaybeAsyncConverter<TFrom, TTo> = MaybeAsyncFunction<Converter<TFrom, TTo>>;
|
|
export type AsyncBiConverter<TFromFirst, TFromSecond, TTo> = AsyncFunction<BiConverter<TFromFirst, TFromSecond, TTo>>;
|
|
export type MaybeAsyncBiConverter<TFromFirst, TFromSecond, TTo> = MaybeAsyncFunction<BiConverter<TFromFirst, TFromSecond, TTo>>;
|
|
export type AsyncAction<T> = AsyncFunction<Action<T>>;
|
|
export type MaybeAsyncAction<T> = MaybeAsyncFunction<Action<T>>;
|
|
export type AsyncAccumulator<TElement, TAccumulator> = AsyncFunction<Accumulator<TElement, TAccumulator>>;
|
|
export type MaybeAsyncAccumulator<T, U> = MaybeAsyncFunction<Accumulator<T, U>>;
|
|
export type AsyncComparer<T> = AsyncFunction<Comparer<T>>;
|
|
export type MaybeAsyncComparer<T> = MaybeAsyncFunction<Comparer<T>>;
|
|
export type AsyncEquater<T> = AsyncFunction<Equater<T>>;
|
|
export type MaybeAsyncEquater<T> = MaybeAsyncFunction<Equater<T>>;
|