neverthrow
neverthrow copied to clipboard
.match with functions that return Result<., .>
Currently it does not seem possible to handle both Ok
and Err
at the same time. Note that this behavior is different from .andThen(...).orElse(...)
or .orElse(...).andThen(...)
as the first of the two chained functions may have its return value handled by the second of the two. As far as I am aware there is no neat way of handling this currently. .match
comes close, but returns a Promise
rather than ResultAsync
when applied to ResultAsync
.
I propose adding the following:
declare class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {
fork<A, B>(ok: (t: T) => Result<A, B> | ResultAsync<A, B>, _err: (e: E) => Result<A, B> | ResultAsync<A, B>): ResultAsync<A, B>
}
I am willing to submit a PR if this idea is accepted