export interface IEither { ok?: T; err?: E; mapBoth: ( errBranch: (e: E) => Ee, okBranch: (o: T) => Tt, ) => IEither; } export class Either implements IEither { private constructor(readonly err?: E, readonly ok?: T) {} public mapBoth(errBranch: (e: E) => Ee, okBranch: (t: T) => Tt) { if (this.err) return new Either(errBranch(this.err)); return new Either(undefined, okBranch(this.ok!)); } static left(e: E) { return new Either(e); } static right(t: T) { return new Either(undefined, t); } }