<E extends Cause.Done>(input: Cause.Cause<E>): Result.Result<
Cause.Done,
Cause.Cause<Exclude<E, Cause.Done>>
>Finds a Cause.Done failure in a cause whose done value is not used.
When to use
Use to detect Cause.Done completion in a Cause when the completion value
is not part of the downstream logic.
Details
Returns a successful Result with the done marker when present, otherwise
returns a failed Result with the non-done cause.
export const const filterDoneVoid: <
E extends Cause.Done
>(
input: Cause.Cause<E>
) => Result.Result<
Cause.Done,
Cause.Cause<Exclude<E, Cause.Done>>
>
Finds a Cause.Done failure in a cause whose done value is not used.
When to use
Use to detect Cause.Done completion in a Cause when the completion value
is not part of the downstream logic.
Details
Returns a successful Result with the done marker when present, otherwise
returns a failed Result with the non-done cause.
filterDoneVoid: <function (type parameter) E in <E extends Cause.Done>(input: Cause.Cause<E>): Result.Result<Cause.Done, Cause.Cause<Exclude<E, Cause.Done>>>E extends import CauseCause.interface Done<A = void>A graceful completion signal for queues and streams.
When to use
Use to model normal producer completion through a stream or queue error
channel.
Details
Done indicates that a producer has finished normally — no more elements
will arrive. It is distinct from an error or interruption; it represents
successful completion. The optional value field can carry a final
leftover payload.
Example (Signaling queue completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
yield* Queue.offer(queue, 1)
yield* Queue.end(queue)
const result = yield* Effect.flip(Queue.take(queue))
console.log(Cause.isDone(result)) // true
})
Companion namespace for the Done interface.
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done>(
input: Cause.Cause<E>(parameter) input: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
input: import CauseCause.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <E extends Cause.Done>(input: Cause.Cause<E>): Result.Result<Cause.Done, Cause.Cause<Exclude<E, Cause.Done>>>E>
) => import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<import CauseCause.interface Done<A = void>A graceful completion signal for queues and streams.
When to use
Use to model normal producer completion through a stream or queue error
channel.
Details
Done indicates that a producer has finished normally — no more elements
will arrive. It is distinct from an error or interruption; it represents
successful completion. The optional value field can carry a final
leftover payload.
Example (Signaling queue completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
yield* Queue.offer(queue, 1)
yield* Queue.end(queue)
const result = yield* Effect.flip(Queue.take(queue))
console.log(Cause.isDone(result)) // true
})
Companion namespace for the Done interface.
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done, import CauseCause.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) E in <E extends Cause.Done>(input: Cause.Cause<E>): Result.Result<Cause.Done, Cause.Cause<Exclude<E, Cause.Done>>>E, import CauseCause.interface Done<A = void>A graceful completion signal for queues and streams.
When to use
Use to model normal producer completion through a stream or queue error
channel.
Details
Done indicates that a producer has finished normally — no more elements
will arrive. It is distinct from an error or interruption; it represents
successful completion. The optional value field can carry a final
leftover payload.
Example (Signaling queue completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
yield* Queue.offer(queue, 1)
yield* Queue.end(queue)
const result = yield* Effect.flip(Queue.take(queue))
console.log(Cause.isDone(result)) // true
})
Companion namespace for the Done interface.
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done>>> = import FilterFilter.const composePassthrough: {
<InputL, PassL, PassR, FailR>(
right: Filter<PassL, PassR, FailR>
): <FailL>(
left: Filter<InputL, PassL, FailL>
) => Filter<InputL, PassR, InputL>
<InputL, PassL, FailL, PassR, FailR>(
left: Filter<InputL, PassL, FailL>,
right: Filter<PassL, PassR, FailR>
): Filter<InputL, PassR, InputL>
}
composePassthrough(
import CauseCause.const findError: <E>(
self: Cause<E>
) => Result.Result<E, Cause<never>>
Returns a Result whose success value is the first typed error value E
from a Fail reason in the cause. If the cause has no Fail reason,
the failure value is the original cause narrowed to Cause<never>, because
it contains no typed error reasons.
When to use
Use when you need the first typed error value from a Cause as a Result
that preserves the original cause when no match is found.
Example (Extracting the first error value)
import { Cause, Result } from "effect"
const result = Cause.findError(Cause.fail("error"))
if (!Result.isFailure(result)) {
console.log(result.success) // "error"
}
findError,
(e: Ee) => import CauseCause.const isDone: (
u: unknown
) => u is Done<any>
Checks whether an arbitrary value is a Done signal.
Example (Checking the runtime type)
import { Cause } from "effect"
console.log(Cause.isDone(Cause.Done())) // true
console.log(Cause.isDone("not done")) // false
isDone(e: Ee) ? import ResultResult.const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(e: E & Cause.Done<any>e) : import ResultResult.const fail: <E>(
left: E
) => Result<never, E>
Creates a Result holding a Failure value.
When to use
Use to represent a failed Result with a typed failure value.
Details
- The success type
A defaults to never
Example (Creating a failure)
import { Result } from "effect"
const result = Result.fail("Something went wrong")
console.log(Result.isFailure(result))
// Output: true
fail(e: Ee)
) as any