Package: effect
Module: Array
Adds a new array variable to a do-notation scope, producing the cartesian product with all previous bindings.
When to use
Use to add another array-producing binding to an Array.Do pipeline, pairing
each existing scope with every value returned by the callback.
Details
Each bind call adds a named property to the accumulated object. The
callback receives the current scope and must return an array. This is
equivalent to flatMap plus merging the new value into the scope object.
Example (Binding two arrays)
import { Array, pipe } from "effect"
const result = pipe(
Array.Do,
Array.bind("x", () => [1, 2]),
Array.bind("y", () => ["a", "b"])
)
console.log(result)
// [{ x: 1, y: "a" }, { x: 1, y: "b" }, { x: 2, y: "a" }, { x: 2, y: "b" }]
See
Do — start a do-notation pipelinebindTo — name the first array in a pipelinelet — add a plain computed valueSignature
declare const bind: { <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; }
Since v3.2.0