<E>(cause: Cause.Cause<E>): Result.Result<
Cause.Done.Extract<E>,
Cause.Cause<ExcludeDone<E>>
>Filters a Cause to extract the leftover value from done errors.
When to use
Use to extract only the leftover value carried by a Cause.Done completion
signal.
export const const filterDoneLeftover: <E>(
cause: Cause.Cause<E>
) => Result.Result<
Cause.Done.Extract<E>,
Cause.Cause<ExcludeDone<E>>
>
Filters a Cause to extract the leftover value from done errors.
When to use
Use to extract only the leftover value carried by a Cause.Done completion
signal.
filterDoneLeftover: <function (type parameter) E in <E>(cause: Cause.Cause<E>): Result.Result<Cause.Done.Extract<E>, Cause.Cause<ExcludeDone<E>>>E>(
cause: Cause.Cause<E>(parameter) cause: {
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;
}
cause: import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<function (type parameter) E in <E>(cause: Cause.Cause<E>): Result.Result<Cause.Done.Extract<E>, Cause.Cause<ExcludeDone<E>>>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.declareDone.type Cause.Done.Extract = /*unresolved*/ anyExtract<function (type parameter) E in <E>(cause: Cause.Cause<E>): Result.Result<Cause.Done.Extract<E>, Cause.Cause<ExcludeDone<E>>>E>, import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<type ExcludeDone<E> =
E extends Cause.Done<any> ? never : E
Excludes Cause.Done completion signals from an error type union.
When to use
Use to describe the ordinary error type that remains after Cause.Done
completion signals have been handled or filtered out of an error union.
ExcludeDone<function (type parameter) E in <E>(cause: Cause.Cause<E>): Result.Result<Cause.Done.Extract<E>, Cause.Cause<ExcludeDone<E>>>E>>> = import FilterFilter.composePassthrough(
import CauseCause.findError,
(e: anye) => import CauseCause.isDone(e: anye) ? 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: anye.value) : 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: anye)
) as any