UNPKG

typescript-functional-extensions

Version:

A TypeScript implementation of synchronous and asynchronous Maybe and Result monads

46 lines (45 loc) 2.02 kB
export type FunctionOfTtoK<T, K> = (v: T) => K; export type AsyncFunctionOfTtoK<T, K> = (v: T) => Promise<K>; export type FunctionOfT<T> = () => T; export type AsyncFunctionOfT<T> = () => Promise<T>; export type Predicate = () => boolean; export type PredicateOfT<T> = (v: T) => boolean; export type ActionOfT<T> = (v: T) => void; export type AsyncActionOfT<T> = (v: T) => Promise<void>; export type Action = () => void; export type AsyncAction = () => Promise<void>; export type ActionNever = () => never; export type Some<T> = T extends None ? never : T; export type None = null | undefined | void; export type Known<TValue> = Exclude<unknown, TValue>; export type ErrorHandler<TError> = FunctionOfTtoK<unknown, Some<TError>>; export declare const never: ActionNever; export declare function isDefined<T>(value: T | None): value is T; export declare function isSome<T>(value: Some<T> | None): value is Some<T>; export declare function isNone<T>(value: Some<T> | None): value is None; export declare function isFunction(value: unknown): value is Function; export declare function isPromise<TValue>(value: unknown): value is Promise<TValue>; export type MaybeMatcher<TValue, TNewValue> = { some: FunctionOfTtoK<TValue, Some<TNewValue>>; none: FunctionOfT<Some<TNewValue>>; }; export type MaybeMatcherNoReturn<TValue> = { some: ActionOfT<TValue>; none: Action; }; export type ResultMatcher<TValue, TError, TNewValue> = { success: FunctionOfTtoK<TValue, Some<TNewValue>>; failure: FunctionOfTtoK<TError, Some<TNewValue>>; }; export type ResultMatcherNoReturn<TValue, TError> = { success: ActionOfT<TValue>; failure: ActionOfT<TError>; }; /** * Sourced from https://github.com/ReactiveX/rxjs/blob/7268bd31d1cb30cf01a1a69a7b14458e15b76b58/src/internal/util/pipe.ts * @param fns * @returns */ export declare function pipeFromArray<T, R>(fns: Array<FunctionOfTtoK<T, R>>): FunctionOfTtoK<T, R>; export declare function noop(): void; export declare function noop<T>(value: Some<T>): Some<T>;