function / @typed/fx

Sink.collect

Collects all values into an array. Pass a Ref<ReadonlyArray<A>> (e.g. Ref.make([])); after running, read the result with Ref.get(ref).

Package version
2.0.0-beta.13
Category
Collecting values
Since
1.0.0
Member of
Sink

Import

import { Sink } from "@typed/fx";

Access Sink.collect through the imported Sink export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

export declare function collect<A, E>(ref: Ref.Ref<ReadonlyArray<A>>): Sink<A, E, never>;

Why

Collection remains an explicit consumer concern and the accumulated result can be read without changing the producer.

Ownership and lifetime

The caller owns the Ref. Each success returns a lazy atomic Ref.update that allocates a new array. Serialized producers collect in callback-Effect execution order. Concurrent updates remain atomic, but execution scheduling—not invocation order—determines array order. Failures are ignored.

Examples

import { Effect, Ref } from "effect"
import * as Sink from "@typed/fx/Sink"
const program = Effect.gen(function* () {
  const values = yield* Ref.make<ReadonlyArray<number>>([])
  return Sink.collect(values)
})

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source