diff options
Diffstat (limited to 'u/fn/either.ts')
-rw-r--r-- | u/fn/either.ts | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/u/fn/either.ts b/u/fn/either.ts index bf90f16..54f9fc2 100644 --- a/u/fn/either.ts +++ b/u/fn/either.ts @@ -32,14 +32,13 @@ export class Either<E, T> implements IEither<E, T> { private readonly self: Left<E> | Right<T>; private constructor( - err?: E, - ok?: T, + init: { err?: E, ok?: T }, public readonly _tag: IEitherTag = iEitherTag, ) { this.self = <Left<E> | Right<T>>{ - isLeft: typeof err !== "undefined", - isRight: typeof ok !== "undefined", - value: typeof err !== "undefined" ? err : ok!, + isLeft: "err" in init, + isRight: "ok" in init, + value: init.err ?? init.ok!, }; } @@ -86,10 +85,11 @@ export class Either<E, T> implements IEither<E, T> { } static left<E, T>(e: E): IEither<E, T> { - return new Either<E, T>(e, undefined); + return new Either<E, T>({ err: e}); } + static right<E, T>(t: T): IEither<E, T> { - return new Either<E, T>(undefined, t); + return new Either<E, T>({ok: t}); } static fromFailable<E, T>(s: Supplier<T>): IEither<E, T> { |