@unthrown/effect
@unthrown/effect
Functions
fromEffect()
function fromEffect<T, E>(effect): AsyncResult<T, E>;Defined in: index.ts:165
Run an Effect and collect its outcome as an AsyncResult.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
effect | Effect<T, E> | the effect to run. |
Returns
AsyncResult<T, E>
Remarks
The effect must need no environment (R = never). It is run to an Exit (which never rejects), then folded with fromExit: success → Ok, a modeled failure → Err, a die/interruption → Defect. The returned AsyncResult never throws when awaited.
fromEither()
function fromEither<T, E>(either): Result<T, E>;Defined in: index.ts:120
Convert an Effect Either into a Result.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
either | Either<T, E> | the either to convert. |
Returns
Result<T, E>
Remarks
Right → Ok, Left → Err. An Either carries no defect, so the result is never a Defect.
fromExit()
function fromExit<T, E>(exit): Result<T, E>;Defined in: index.ts:70
Convert an Effect Exit into a Result — the inverse of toExit.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
exit | Exit<T, E> | the exit to convert. |
Returns
Result<T, E>
Remarks
Exit.Success → Ok. For a failure, the enclosing Cause is reduced:
- a
Cause.diebecomes aDefect, - otherwise a
Cause.failbecomes the modeledErr, - a pure interruption (or empty cause) becomes a
Defect.
A Defect dominates a modeled failure in a composite cause — the same rule unthrown's all uses, on the principle that an unexpected failure is the more severe signal.
toEffect()
Call Signature
function toEffect<T, E>(source): Effect<T, E>;Defined in: index.ts:140
Lift a Result or AsyncResult into an Effect.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
source | Result<T, E> | the result, or async result, to lift. |
Returns
Effect<T, E>
Remarks
Ok → Effect.succeed, Err → Effect.fail, Defect → Effect.die. The resulting Effect needs no environment (R = never). An AsyncResult is awaited inside the effect (it never rejects), so this is the AsyncResult → Effect direction too.
Call Signature
function toEffect<T, E>(source): Effect<T, E>;Defined in: index.ts:141
Lift a Result or AsyncResult into an Effect.
Type Parameters
| Type Parameter | Description |
|---|---|
T | the success value type. |
E | the modeled error type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
source | AsyncResult<T, E> | the result, or async result, to lift. |
Returns
Effect<T, E>
Remarks
Ok → Effect.succeed, Err → Effect.fail, Defect → Effect.die. The resulting Effect needs no environment (R = never). An AsyncResult is awaited inside the effect (it never rejects), so this is the AsyncResult → Effect direction too.
toEither()
function toEither<T, E>(result, onDefect): Either<T, E>;Defined in: index.ts:98
Convert a Result into an Effect Either, 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
Either<T, E>
Remarks
Either has no defect channel, so a Defect cannot pass through silently — onDefect must fold its cause into a modeled error E (a Left). This is the boundary-qualification rule (Thesis #3) applied on the way out: Ok → Right, Err → Left, Defect → Left(onDefect(cause)).
toExit()
function toExit<T, E>(result): Exit<T, E>;Defined in: index.ts:43
Convert a Result into an Effect Exit — a bijection, since both carry three channels.
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. |
Returns
Exit<T, E>
Remarks
Ok → Exit.succeed, Err → Exit.fail (a modeled Cause.fail), and Defect → Exit.die (an unexpected Cause.die). Round-trips with fromExit.
Example
import { ok } from "unthrown";
import { toExit } from "@unthrown/effect";
toExit(ok(1)); // Exit.succeed(1)