# reduce

Reduces values into a single result using a pure function. Pass a `Ref<B>`
(e.g. from `Ref.make(initial)`); after running, read the result with `Ref.get(ref)`.

## Signatures

```ts
export declare function reduce<A, B, E>(ref: Ref.Ref<B>, f: (b: B, a: A) => B): Sink<A, E, never>;
```

## Why

An existing Ref provides an explicit, independently readable result location for consumer-side
aggregation.

## Ownership and lifetime

The caller owns the Ref. Each success returns a lazy atomic `Ref.update`; invoking `onSuccess`
does not update immediately. If the producer executes callback Effects serially, values reduce in
that execution order. Concurrent execution is still atomic but may be scheduled in a different
order than callback invocation. Failures are ignored and a thrown reducer exception is a defect.

## Examples

```ts
import { Effect, Ref } from "effect"
import * as Sink from "@typed/fx/Sink"
const program = Effect.gen(function* () {
  const total = yield* Ref.make(0)
  return Sink.reduce(total, (sum, n: number) => sum + n)
})
```
