function / @typed/fx

Sink.last

Keeps only the last value. Pass a Ref<Option.Option<A>> (e.g. Ref.make(Option.none())); after running, read the result with Ref.get(ref).

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

Import

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

Access Sink.last 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 last<A, E>(ref: Ref.Ref<Option.Option<A>>): Sink<A, E, never>;

Why

The latest observed value can be retained independently of producer completion.

Ownership and lifetime

The caller owns the Ref. Each success returns a lazy atomic Ref.set. With serialized callback Effects the last callback wins; with concurrent execution the last set to execute wins, which may differ from invocation order. Failures are ignored and the sink acquires no resources.

Examples

import { Effect, Option, Ref } from "effect"
import * as Sink from "@typed/fx/Sink"
const program = Effect.gen(function* () {
  const latest = yield* Ref.make<Option.Option<number>>(Option.none())
  return Sink.last(latest)
})

Other public imports

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

Source