<N extends string, A extends object, B, L2>(
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Result<B, L2>
): <L1>(
self: Result<A, L1>
) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>
<A extends object, L1, N extends string, B, L2>(
self: Result<A, L1>,
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Result<B, L2>
): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>Adds a named field to the do-notation accumulator by running a Result-producing
function that receives the current accumulated object.
When to use
Use when you need to add a Result-producing step to a Result
do-notation pipeline and store its successful value under a named field in
the accumulated object.
Details
- Short-circuits on the first
Failure - The field name must not collide with existing keys
- Use let for pure (non-Result) computed fields
Example (Binding Result values)
import { pipe, Result } from "effect"
const result = pipe(
Result.Do,
Result.bind("x", () => Result.succeed(2)),
Result.bind("y", ({ x }) => Result.succeed(x + 3))
)
console.log(result)
// Output: { _tag: "Success", success: { x: 2, y: 5 }, ... }export const const bind: {
<N extends string, A extends object, B, L2>(
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Result<B, L2>
): <L1>(self: Result<A, L1>) => Result<
{
[K in N | keyof A]: K extends keyof A
? A[K]
: B
},
L1 | L2
>
<A extends object, L1, N extends string, B, L2>(
self: Result<A, L1>,
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Result<B, L2>
): Result<
{
[K in N | keyof A]: K extends keyof A
? A[K]
: B
},
L1 | L2
>
}
Adds a named field to the do-notation accumulator by running a Result-producing
function that receives the current accumulated object.
When to use
Use when you need to add a Result-producing step to a Result
do-notation pipeline and store its successful value under a named field in
the accumulated object.
Details
- Short-circuits on the first
Failure
- The field name must not collide with existing keys
- Use
let
for pure (non-Result) computed fields
Example (Binding Result values)
import { pipe, Result } from "effect"
const result = pipe(
Result.Do,
Result.bind("x", () => Result.succeed(2)),
Result.bind("y", ({ x }) => Result.succeed(x + 3))
)
console.log(result)
// Output: { _tag: "Success", success: { x: 2, y: 5 }, ... }
bind: {
<function (type parameter) N in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>N extends string, function (type parameter) A in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A extends object, function (type parameter) B in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>B, function (type parameter) L2 in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L2>(
name: Exclude<N, keyof A>name: type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) N in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>N, keyof function (type parameter) A in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A>,
f: (a: NoInfer<A>) => Result<B, L2>f: (a: NoInfer<A>a: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A>) => 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) B in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>B, function (type parameter) L2 in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L2>
): <function (type parameter) L1 in <L1>(self: Result<A, L1>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L1>(self: Result<A, L1>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 <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A, function (type parameter) L1 in <L1>(self: Result<A, L1>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L1>) => 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) KK in function (type parameter) N in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>N | keyof function (type parameter) A in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A]: function (type parameter) KK extends keyof function (type parameter) A in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A ? function (type parameter) A in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A[function (type parameter) KK] : function (type parameter) B in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>B }, function (type parameter) L1 in <L1>(self: Result<A, L1>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L1 | function (type parameter) L2 in <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): <L1>(self: Result<A, L1>) => Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L2>
<function (type parameter) A in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A extends object, function (type parameter) L1 in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L1, function (type parameter) N in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>N extends string, function (type parameter) B in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>B, function (type parameter) L2 in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L2>(
self: Result<A, L1>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 extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A, function (type parameter) L1 in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L1>,
name: Exclude<N, keyof A>name: type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) N in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>N, keyof function (type parameter) A in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A>,
f: (a: NoInfer<A>) => Result<B, L2>f: (a: NoInfer<A>a: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A>) => 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) B in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>B, function (type parameter) L2 in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L2>
): 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) KK in function (type parameter) N in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>N | keyof function (type parameter) A in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A]: function (type parameter) KK extends keyof function (type parameter) A in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A ? function (type parameter) A in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>A[function (type parameter) KK] : function (type parameter) B in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>B }, function (type parameter) L1 in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L1 | function (type parameter) L2 in <A extends object, L1, N extends string, B, L2>(self: Result<A, L1>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Result<B, L2>): Result<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }, L1 | L2>L2>
} = import doNotationdoNotation.const bind: <F extends TypeLambda>(
map: Map<F>,
flatMap: FlatMap<F>
) => {
<
N extends string,
A extends object,
R2,
O2,
E2,
B
>(
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>
): <R1, O1, E1>(
self: Kind<F, R1, O1, E1, A>
) => Kind<
F,
R1 & R2,
O1 | O2,
E1 | E2,
{
[K in keyof A | N]: K extends keyof A
? A[K]
: B
}
>
<
R1,
O1,
E1,
A extends object,
N extends string,
R2,
O2,
E2,
B
>(
self: Kind<F, R1, O1, E1, A>,
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>
): Kind<
F,
R1 & R2,
O1 | O2,
E1 | E2,
{
[K in keyof A | N]: K extends keyof A
? A[K]
: B
}
>
}
bind<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, const flatMap: {
<A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(
self: Result<A, E>
) => Result<A2, E | E2>
<A, E, A2, E2>(
self: Result<A, E>,
f: (a: A) => Result<A2, E2>
): Result<A2, E | E2>
}
Chains a function that returns a Result onto a successful value.
When to use
Use to sequence Result-returning computations that should short-circuit on
failure.
Details
- If
self is a Success, applies f to the value and returns the resulting Result
- If
self is a Failure, short-circuits and returns it unchanged
- The error types are merged into a union (
E | E2)
- This is the monadic
bind / >>= for Result
Example (Validating sequentially)
import { pipe, Result } from "effect"
const result = pipe(
Result.succeed(5),
Result.flatMap((n) =>
n > 0 ? Result.succeed(n * 2) : Result.fail("not positive")
)
)
console.log(result)
// Output: { _tag: "Success", success: 10, ... }
flatMap)