Hyperlinkv0.8.0-beta.28

Array

Array.bindToconsteffect/Array.ts:4781
<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
}>

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 }]
do notationDobind
Source effect/Array.ts:47814 lines
export 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 }>
} = internalDoNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any