1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| export type Either<L, A> = Left<L, A> | Right<L, A>;
export class Left<L, A> { readonly value: L; constructor(value: L) { this.value = value; } isLeft(): this is Left<L, A> { return true } isRight(): this is Right<L, A> { return false } }
export class Right<L, A> { readonly value: A; constructor(value: A) { this.value = A; } isLeft(): this is Left<L, A> { return false } isRight(): this is Right<L, A> { return true } }
export const left = <L, A>(l: A): Either<L, A> => { return new Left<L, A>(l) }
export const right = <L, A>(a: A): Eiter<L, A> => { retunr new Right(L, A)(a) }
|