UNPKG

typed-utilities

Version:
36 lines (35 loc) 1.31 kB
declare enum EitherTag { Left = "left", Right = "right" } export declare type Left<T> = [tag: EitherTag.Left, value: T]; export declare type Right<T> = [tag: EitherTag.Right, value: T]; export declare type Either<L, R> = Left<L> | Right<R>; declare function isLeft<L>(either: Either<L, unknown>): either is Left<L>; declare function assertLeft<L>(either: Either<L, unknown>, message?: string): asserts either is Left<L>; declare function isRight<R>(either: Either<unknown, R>): either is Right<R>; declare function assertRight<R>(either: Either<unknown, R>, message?: string): asserts either is Right<R>; export declare type Match<L, R, IfLeft, IfRight> = { readonly left: (value: L) => IfLeft; readonly right: (value: R) => IfRight; }; export declare const Either: { is: { left: typeof isLeft; right: typeof isRight; }; to: { leftValue: <L>(either: Left<L>) => L; rightValue: <R>(either: Right<R>) => R; }; assert: { left: typeof assertLeft; right: typeof assertRight; }; of: { left: <L_1>(value: L_1) => Left<L_1>; right: <R_1>(value: R_1) => Right<R_1>; }; match: <L_2, R_2, IfLeft, IfRight>(either: Either<L_2, R_2>, match: Match<L_2, R_2, IfLeft, IfRight>) => IfLeft | IfRight; }; export {};