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