1
0

move types around

This commit is contained in:
2024-05-09 23:55:40 +02:00
parent fccebc61b6
commit 679a61f040
10 changed files with 58 additions and 60 deletions

30
src/types.ts Normal file
View File

@@ -0,0 +1,30 @@
export type Predicate<T> = (obj: T) => boolean;
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) => void;
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 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 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 MaybeAsyncPredicate<T> = MaybeAsyncFunction<Predicate<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>>;