UNPKG

ts-sum-types

Version:

Algebraic sum types for TypeScript, designed after Rust's enums

13 lines (12 loc) 272 B
export class VariantClass { constructor(tag, value) { this.tag = tag; this.value = value; } match(fns) { fns[this.tag](...this.value); } } export function Variant(tag, value) { return new VariantClass(tag, value); }