<A, E>(self: Result<A, E>): E | AUnwraps a Result into A | E by returning the inner value regardless
of whether it is a success or failure.
Details
Success<A>returnsAFailure<E>returnsE- Useful when both channels share a compatible type
Example (Extracting the inner value)
import { Result } from "effect"
console.log(Result.merge(Result.succeed(42)))
// Output: 42
console.log(Result.merge(Result.fail("error")))
// Output: "error"Source effect/Result.ts:10691 lines
export const const merge: <A, E>(
self: Result<A, E>
) => E | A
Unwraps a Result into A | E by returning the inner value regardless
of whether it is a success or failure.
Details
Success<A> returns A
Failure<E> returns E
- Useful when both channels share a compatible type
Example (Extracting the inner value)
import { Result } from "effect"
console.log(Result.merge(Result.succeed(42)))
// Output: 42
console.log(Result.merge(Result.fail("error")))
// Output: "error"
merge: <function (type parameter) A in <A, E>(self: Result<A, E>): E | AA, function (type parameter) E in <A, E>(self: Result<A, E>): E | AE>(self: Result<A, E>self: type Result<A, E = never> = Success<A, E> | 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<function (type parameter) A in <A, E>(self: Result<A, E>): E | AA, function (type parameter) E in <A, E>(self: Result<A, E>): E | AE>) => function (type parameter) E in <A, E>(self: Result<A, E>): E | AE | function (type parameter) A in <A, E>(self: Result<A, E>): E | AA = const match: {
<E, B, A, C = B>(options: {
readonly onFailure: (error: E) => B
readonly onSuccess: (ok: A) => C
}): (self: Result<A, E>) => B | C
<A, E, B, C = B>(
self: Result<A, E>,
options: {
readonly onFailure: (error: E) => B
readonly onSuccess: (ok: A) => C
}
): B | C
}
match({ onFailure: (error: E) => A | EonFailure: import identityidentity, onSuccess: (ok: A) => A | EonSuccess: import identityidentity })Referenced by 1 symbols