Package: effect
Module: Array
Adds a computed plain value to the do-notation scope without introducing a new array dimension.
When to use
Use when each do-notation branch needs a derived field from the current bindings without multiplying the number of branches.
Details
Unlike bind, the callback returns a single value instead of an array, so
no cartesian product occurs. Use this for derived or intermediate values
that depend on previously bound variables.
Example (Adding a computed value)
import { Array, pipe } from "effect"
const result = pipe(
Array.Do,
Array.bind("x", () => [1, 2, 3]),
Array.let("doubled", ({ x }) => x * 2)
)
console.log(result)
// [{ x: 1, doubled: 2 }, { x: 2, doubled: 4 }, { x: 3, doubled: 6 }]
See
Do — start a do-notation pipelinebind — introduce an array variable (produces cartesian product)Signature
declare const let: { <N extends string, B, A extends object>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => B): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; <N extends string, A extends object, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => B): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; }
Since v3.2.0