Hyperlinkv0.8.0-beta.28

Array

ReadonlyArray<{}>

Provides the starting point for the "do simulation" — an array comprehension pattern.

When to use

Use when you want array-comprehension style code with do notation.

Details

Use bind to introduce array variables and let for plain values. Each bind produces the cartesian product of all bound variables, like nested loops. Use filter and map in the pipeline to add conditions and transformations.

Example (Building array comprehensions with do notation)

import { Array, pipe } from "effect"

const result = pipe(
  Array.Do,
  Array.bind("x", () => [1, 3, 5]),
  Array.bind("y", () => [2, 4, 6]),
  Array.filter(({ x, y }) => x < y),
  Array.map(({ x, y }) => [x, y] as const)
)
console.log(result) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]
do notationbindlet_bindTo
Source effect/Array.ts:46991 lines
export const Do: ReadonlyArray<{}> = of({})