<N extends string>(name: N): <A>(
self: Option<A>
) => Option<{ [K in N]: A }>
<A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A }>Gives a name to the value of an Option, creating a single-key record
inside Some. Starting point for the do notation pipeline.
When to use
Use when you need to start an Option do notation chain by naming the first
value.
Example (Starting do notation)
import { Option, pipe } from "effect"
import * as assert from "node:assert"
const result = pipe(
Option.some(2),
Option.bindTo("x"),
Option.bind("y", () => Option.some(3)),
Option.let("sum", ({ x, y }) => x + y)
)
assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))export const const bindTo: {
<N extends string>(name: N): <A>(
self: Option<A>
) => Option<{
[K in N]: A
}>
<A, N extends string>(
self: Option<A>,
name: N
): Option<{
[K in N]: A
}>
}
Gives a name to the value of an Option, creating a single-key record
inside Some. Starting point for the do notation pipeline.
When to use
Use when you need to start an Option do notation chain by naming the first
value.
Example (Starting do notation)
import { Option, pipe } from "effect"
import * as assert from "node:assert"
const result = pipe(
Option.some(2),
Option.bindTo("x"),
Option.bind("y", () => Option.some(3)),
Option.let("sum", ({ x, y }) => x + y)
)
assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
bindTo: {
<function (type parameter) N in <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A; }>N extends string>(name: N extends stringname: function (type parameter) N in <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A; }>N): <function (type parameter) A in <A>(self: Option<A>): Option<{ [K in N]: A; }>A>(self: Option<A>self: 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) A in <A>(self: Option<A>): Option<{ [K in N]: A; }>A>) => 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) KK in function (type parameter) N in <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A; }>N]: function (type parameter) A in <A>(self: Option<A>): Option<{ [K in N]: A; }>A }>
<function (type parameter) A in <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A; }>A, function (type parameter) N in <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A; }>N extends string>(self: Option<A>self: 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) A in <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A; }>A>, name: N extends stringname: function (type parameter) N in <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A; }>N): 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) KK in function (type parameter) N in <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A; }>N]: function (type parameter) A in <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A; }>A }>
} = 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<OptionTypeLambda>(const map: {
<A, B>(f: (a: A) => B): (
self: Option<A>
) => Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => B
): Option<B>
}
Transforms the value inside a Some using the provided function, leaving
None unchanged.
When to use
Use to apply a pure transformation to an Option's present value, especially
when chaining transformations in a pipeline.
Details
Some → applies f and wraps the result in a new Some
None → returns None unchanged
Example (Mapping over an Option)
import { Option } from "effect"
console.log(Option.map(Option.some(2), (n) => n * 2))
// Output: { _id: 'Option', _tag: 'Some', value: 4 }
console.log(Option.map(Option.none(), (n: number) => n * 2))
// Output: { _id: 'Option', _tag: 'None' }
map)