@unthrown/neverthrow
@unthrown/neverthrow
Functions
fromNeverthrow()
function fromNeverthrow<T, E>(result): Result<T, E>;Defined in: index.ts:60
Convert a neverthrow Result into a Result.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
result | Result<T, E> | the neverthrow result to convert. |
Returns
Result<T, E>
Remarks
ok → Ok, err → Err. neverthrow carries no defect, so the result is never a Defect.
fromNeverthrowAsync()
function fromNeverthrowAsync<T, E>(resultAsync): AsyncResult<T, E>;Defined in: index.ts:99
Convert a neverthrow ResultAsync into an AsyncResult.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
resultAsync | ResultAsync<T, E> | the neverthrow async result to convert. |
Returns
AsyncResult<T, E>
Remarks
The async counterpart of fromNeverthrow. A modeled Err stays an Err; an unexpected rejection inside the neverthrow chain becomes a Defect. The returned AsyncResult never throws when awaited.
toNeverthrow()
function toNeverthrow<T, E>(result, onDefect): Result<T, E>;Defined in: index.ts:38
Convert a Result into a neverthrow Result, triaging any defect.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
result | Result<T, E> | the result to convert. |
onDefect | (cause) => E | folds a defect's unknown cause into a modeled E. |
Returns
Result<T, E>
Remarks
neverthrow has no defect channel, so onDefect must fold a Defect's cause into a modeled error E (an Err). Ok → ok, Err → err, Defect → err(onDefect(cause)).
toNeverthrowAsync()
function toNeverthrowAsync<T, E>(asyncResult, onDefect): ResultAsync<T, E>;Defined in: index.ts:78
Convert an AsyncResult into a neverthrow ResultAsync, triaging any defect.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
asyncResult | AsyncResult<T, E> | the async result to convert. |
onDefect | (cause) => E | folds a defect's unknown cause into a modeled E. |
Returns
ResultAsync<T, E>
Remarks
The async counterpart of toNeverthrow: onDefect is required for the same reason. The AsyncResult is awaited (it never rejects) and each settled Result is converted.