export interface Left { readonly left: L; readonly tag: 'Left'; } export interface Right { readonly right: R; readonly tag: 'Right'; } export type Either = Left | Right; export const isLeft = (ml: Either): ml is Left => ml.tag === 'Left'; export const isRight = (mr: Either): mr is Right => mr.tag === 'Right'; export const left = (l: L): Either => ({ left: l, tag: 'Left', }); export const right = (r: R): Either => ({ right: r, tag: 'Right', }); export const match = (onLeft: (l: L) => A, onRight: (r: R) => A) => ( ml: Either ): A => (isLeft(ml) ? onLeft(ml.left) : onRight(ml.right));