diff options
author | Elizabeth <me@liz.coffee> | 2025-06-02 19:27:15 -0700 |
---|---|---|
committer | Elizabeth <me@liz.coffee> | 2025-06-02 19:27:15 -0700 |
commit | 2ae2ebc8aa7c4600f499ab7d2264dcb1d16db4ae (patch) | |
tree | 8db4b1ac04da35bed464cc8e4678f90b9eb6bda2 /u/fn/either.ts | |
parent | a16fbd3eaa165b3226a3b0ed9848b51718aaeafa (diff) | |
download | ci-2ae2ebc8aa7c4600f499ab7d2264dcb1d16db4ae.tar.gz ci-2ae2ebc8aa7c4600f499ab7d2264dcb1d16db4ae.zip |
Fixes when getStdout would throw early
Diffstat (limited to 'u/fn/either.ts')
-rw-r--r-- | u/fn/either.ts | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/u/fn/either.ts b/u/fn/either.ts index 54f9fc2..ffe8033 100644 --- a/u/fn/either.ts +++ b/u/fn/either.ts @@ -32,7 +32,7 @@ export class Either<E, T> implements IEither<E, T> { private readonly self: Left<E> | Right<T>; private constructor( - init: { err?: E, ok?: T }, + init: { err?: E; ok?: T }, public readonly _tag: IEitherTag = iEitherTag, ) { this.self = <Left<E> | Right<T>>{ @@ -85,11 +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>({ err: e}); + return new Either<E, T>({ err: e }); } static right<E, T>(t: T): IEither<E, T> { - return new Either<E, T>({ok: t}); + return new Either<E, T>({ ok: t }); } static fromFailable<E, T>(s: Supplier<T>): IEither<E, T> { @@ -100,12 +100,12 @@ export class Either<E, T> implements IEither<E, T> { } } - static async fromFailableAsync<E, T>(s: Promise<T>): Promise<IEither<E, T>> { - try { - return Either.right<E, T>(await s); - } catch (e) { - return Either.left<E, T>(e as E); - } + static async fromFailableAsync<E, T>( + s: Supplier<Promise<T>>, + ): Promise<IEither<E, T>> { + return await s() + .then((t: T) => Either.right<E, T>(t)) + .catch((e: E) => Either.left<E, T>(e)); } } |