sums-up
Version:
👍 Sums Up ===
25 lines (24 loc) • 845 B
TypeScript
import { Setoid, Show, Unshift } from "./utils";
export declare type Variants = {
[key: string]: unknown[];
};
export declare type VariantNameAndData<T extends Variants> = {
[K in keyof T]: Unshift<T[K], K>;
}[keyof T];
export declare type ExhaustiveCasePattern<T extends Variants, R> = {
[K in keyof T]: (...args: T[K]) => R;
};
export declare type CasePattern<T extends Variants, R> = ExhaustiveCasePattern<T, R> | (Partial<ExhaustiveCasePattern<T, R>> & {
_: () => R;
});
declare abstract class SumType<M extends Variants> implements Setoid, Show {
private variantName;
private data;
constructor(...args: VariantNameAndData<M>);
get kind(): keyof M;
get type(): keyof M;
caseOf<T>(pattern: CasePattern<M, T>): T;
equals(that: SumType<M>): boolean;
toString(): string;
}
export default SumType;