Hyperlinkv0.8.0-beta.28

Array

Array.bindconsteffect/Array.ts:4736
<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 }>

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" }]
do notationDobindTolet_
Source effect/Array.ts:473613 lines
export 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 }>
} = internalDoNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any