effect-io-ai

Package: effect
Module: Array

Array.bindTo

Wraps each array element in an object with the given key, starting a do-notation scope.

When to use

Use when you already have an array and want to start a do-notation pipeline by naming each element.

Details

Equivalent to Array.map(self, (a) => ({ [tag]: a })). This is an alternative to starting with Do plus bind when you already have an array.

Example (Naming an existing array)

import { Array, pipe } from "effect"

const result = pipe(
  [1, 2, 3],
  Array.bindTo("x")
)
console.log(result) // [{ x: 1 }, { x: 2 }, { x: 3 }]

See

Signature

declare const bindTo: { <N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A; }>; <A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A; }>; }

Source

Since v3.2.0