<E>(input: Cause<E>): Option<E>Returns the first typed error value E from a cause wrapped in
Option.some, or Option.none if no Fail reason exists.
When to use
Use when you need the first typed error value from a Cause as an Option,
discarding the original cause.
Example (Extracting an error as Option)
import { Cause, Option } from "effect"
const some = Cause.findErrorOption(Cause.fail("error"))
console.log(Option.isSome(some)) // true
const none = Cause.findErrorOption(Cause.die("defect"))
console.log(Option.isNone(none)) // trueexport const const findErrorOption: <E>(
input: Cause<E>
) => Option<E>
Returns the first typed error value E from a cause wrapped in
Option.some, or Option.none if no Fail reason exists.
When to use
Use when you need the first typed error value from a Cause as an Option,
discarding the original cause.
Example (Extracting an error as Option)
import { Cause, Option } from "effect"
const some = Cause.findErrorOption(Cause.fail("error"))
console.log(Option.isSome(some)) // true
const none = Cause.findErrorOption(Cause.die("defect"))
console.log(Option.isNone(none)) // true
findErrorOption: <function (type parameter) E in <E>(input: Cause<E>): Option<E>E>(input: 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: 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>(input: Cause<E>): Option<E>E>) => type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) E in <E>(input: Cause<E>): Option<E>E> = import effecteffect.const findErrorOption: <E>(
input: Cause<E>
) => Option<E>
findErrorOption