export class Left { readonly value: L; constructor(value: L) { this.value = value; } isRight(): this is Right { return false; } isLeft(): this is Left { return true; } } export class Right { readonly value: R; constructor(value: R) { this.value = value; } isRight(): this is Right { return true; } isLeft(): this is Left { return false; } } export type Either = Left | Right; export const left = (value: L): Either => { return new Left(value); }; export const right = (value: R): Either => { return new Right(value); };