<N extends string>(name: N): <R, L>(
self: Result<R, L>
) => Result<Record<N, R>, L>
<R, L, N extends string>(self: Result<R, L>, name: N): Result<
Record<N, R>,
L
>Wraps the success value of a Result into a named field, producing a
Result<Record<N, A>>.
When to use
Use to name the success value of an existing Result before continuing a
do-notation pipeline.
Details
This is typically used to start a do-notation chain from an existing
Result.
Example (Wrapping a value into a named field)
import { pipe, Result } from "effect"
const result = pipe(
Result.succeed(42),
Result.bindTo("answer")
)
console.log(result)
// Output: { _tag: "Success", success: { answer: 42 }, ... }export const const bindTo: {
<N extends string>(name: N): <R, L>(
self: Result<R, L>
) => Result<Record<N, R>, L>
<R, L, N extends string>(
self: Result<R, L>,
name: N
): Result<Record<N, R>, L>
}
Wraps the success value of a Result into a named field, producing a
Result<Record<N, A>>.
When to use
Use to name the success value of an existing Result before continuing a
do-notation pipeline.
Details
This is typically used to start a do-notation chain from an existing
Result.
Example (Wrapping a value into a named field)
import { pipe, Result } from "effect"
const result = pipe(
Result.succeed(42),
Result.bindTo("answer")
)
console.log(result)
// Output: { _tag: "Success", success: { answer: 42 }, ... }
bindTo: {
<function (type parameter) N in <N extends string>(name: N): <R, L>(self: Result<R, L>) => Result<Record<N, R>, L>N extends string>(name: N extends stringname: function (type parameter) N in <N extends string>(name: N): <R, L>(self: Result<R, L>) => Result<Record<N, R>, L>N): <function (type parameter) R in <R, L>(self: Result<R, L>): Result<Record<N, R>, L>R, function (type parameter) L in <R, L>(self: Result<R, L>): Result<Record<N, R>, L>L>(self: Result<R, L>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) R in <R, L>(self: Result<R, L>): Result<Record<N, R>, L>R, function (type parameter) L in <R, L>(self: Result<R, L>): Result<Record<N, R>, L>L>) => 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<type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<function (type parameter) N in <N extends string>(name: N): <R, L>(self: Result<R, L>) => Result<Record<N, R>, L>N, function (type parameter) R in <R, L>(self: Result<R, L>): Result<Record<N, R>, L>R>, function (type parameter) L in <R, L>(self: Result<R, L>): Result<Record<N, R>, L>L>
<function (type parameter) R in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>R, function (type parameter) L in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>L, function (type parameter) N in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>N extends string>(self: Result<R, L>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) R in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>R, function (type parameter) L in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>L>, name: N extends stringname: function (type parameter) N in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>N): 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<type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<function (type parameter) N in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>N, function (type parameter) R in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>R>, function (type parameter) L in <R, L, N extends string>(self: Result<R, L>, name: N): Result<Record<N, R>, L>L>
} = import doNotationdoNotation.const bindTo: <F extends TypeLambda>(
map: Map<F>
) => {
<N extends string>(name: N): <R, O, E, A>(
self: Kind<F, R, O, E, A>
) => Kind<F, R, O, E, Record<N, A>>
<R, O, E, A, N extends string>(
self: Kind<F, R, O, E, A>,
name: N
): Kind<F, R, O, E, Record<N, A>>
}
bindTo<ResultTypeLambda>(const map: {
<A, A2>(f: (ok: A) => A2): <E>(
self: Result<A, E>
) => Result<A2, E>
<A, E, A2>(
self: Result<A, E>,
f: (ok: A) => A2
): Result<A2, E>
}
Transforms the success channel of a Result, leaving the failure channel unchanged.
When to use
Use to apply a transformation to the success value of a Result while
preserving any existing failure.
Details
- If the result is a
Success, applies f to the value and returns a new Success
- If the result is a
Failure, returns it as-is
- Use
flatMap
if
f returns a Result (to avoid nested Results)
Example (Doubling the success value)
import { pipe, Result } from "effect"
const result = pipe(
Result.succeed(3),
Result.map((n) => n * 2)
)
console.log(result)
// Output: { _tag: "Success", success: 6, ... }
map)