From a16fbd3eaa165b3226a3b0ed9848b51718aaeafa Mon Sep 17 00:00:00 2001 From: Elizabeth Date: Mon, 2 Jun 2025 18:55:32 -0700 Subject: Fixes when the map of an either is expected to be possible undefined --- u/fn/either.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'u/fn/either.ts') 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 implements IEither { private readonly self: Left | Right; private constructor( - err?: E, - ok?: T, + init: { err?: E, ok?: T }, public readonly _tag: IEitherTag = iEitherTag, ) { this.self = | Right>{ - 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 implements IEither { } static left(e: E): IEither { - return new Either(e, undefined); + return new Either({ err: e}); } + static right(t: T): IEither { - return new Either(undefined, t); + return new Either({ok: t}); } static fromFailable(s: Supplier): IEither { -- cgit v1.2.3-70-g09d2