Skip to content

@unthrown/boxed


@unthrown/boxed

Functions

fromBoxed()

ts
function fromBoxed<T, E>(result): Result<T, E>;

Defined in: index.ts:55

Convert a Boxed Result into a Result.

Type Parameters

Type ParameterDescription
Tthe success value type.
Ethe modeled error type.

Parameters

ParameterTypeDescription
resultResult<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()

ts
function fromBoxedFuture<T, E>(future): AsyncResult<T, E>;

Defined in: index.ts:99

Convert a Boxed Future<Result> into an AsyncResult.

Type Parameters

Type ParameterDescription
Tthe success value type.
Ethe modeled error type.

Parameters

ParameterTypeDescription
futureFuture<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()

ts
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 ParameterDescription
Tthe success value type.
Ethe modeled error type.

Parameters

ParameterTypeDescription
resultResult<T, E>the result to convert.
onDefect(cause) => Efolds 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()

ts
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 ParameterDescription
Tthe success value type.
Ethe modeled error type.

Parameters

ParameterTypeDescription
asyncResultAsyncResult<T, E>the async result to convert.
onDefect(cause) => Efolds 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.

Released under the MIT License.