1
0
Files
sequence-js/src/types.ts
Herve BECHER 0fd0e3bada sync
2025-05-24 12:11:44 +02:00

32 lines
2.3 KiB
TypeScript

export type Predicate<T> = (obj: T) => boolean;
export type AnyPredicate<T> = (obj: T) => unknown;
export type TypePredicate<TElement, TType extends TElement> = (obj: TElement) => obj is TType;
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 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 AsyncPredicate<T> = AsyncFunction<Predicate<T>>;
export type AsyncAnyPredicate<T> = AsyncFunction<AnyPredicate<T>>;
export type AsyncTypePredicate<TElement, TType extends TElement> = AsyncFunction<TypePredicate<TElement, TType>>;
export type MaybeAsyncPredicate<T> = MaybeAsyncFunction<Predicate<T>>;
export type MaybeAsyncAnyPredicate<T> = MaybeAsyncFunction<AnyPredicate<T>>;
export type MaybeAsyncTypePredicate<TElement, TType extends TElement> = MaybeAsyncFunction<TypePredicate<TElement, TType>>;
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>>;