@unthrown/boxed
@unthrown/boxed
Functions
fromBoxed()
function fromBoxed<T, E>(result): Result<T, E>;Defined in: index.ts:55
Convert a Boxed 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 Boxed result to convert. |
Returns
Result<T, E>
Remarks
Result.Ok → Ok, Result.Error → Err. Boxed's Result carries no defect, so the result is never a Defect.
fromBoxedFuture()
function fromBoxedFuture<T, E>(future): AsyncResult<T, E>;Defined in: index.ts:99
Convert a Boxed Future<Result> into an AsyncResult.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
future | Future<Result<T, E>> | the Boxed future to convert. |
Returns
AsyncResult<T, E>
Remarks
The async counterpart of fromBoxed. A Result.Error stays an Err; an unexpected rejection of the underlying promise becomes a Defect. The returned AsyncResult never throws when awaited.
toBoxed()
function toBoxed<T, E>(result, onDefect): Result<T, E>;Defined in: index.ts:33
Convert a Result into a Boxed 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
Boxed's Result has no defect channel, so onDefect must fold a Defect's cause into a modeled error E (an Error). Ok → Result.Ok, Err → Result.Error, Defect → Result.Error(onDefect(cause)).
toBoxedFuture()
function toBoxedFuture<T, E>(asyncResult, onDefect): Future<Result<T, E>>;Defined in: index.ts:76
Convert an AsyncResult into a Boxed Future<Result>, 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
Future<Result<T, E>>
Remarks
The async counterpart of toBoxed: onDefect is required for the same reason. The AsyncResult is awaited (it never rejects) and its settled Result is converted, then resolved into the Future.