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]]export const const Do: readonly {}[]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: interface ReadonlyArray<T>ReadonlyArray<{}> = const of: <A>(a: A) => NonEmptyArray<A>Wraps a single value in a NonEmptyArray.
Example (Creating a single-element array)
import { Array } from "effect"
console.log(Array.of(1)) // [1]
of({})