variable / @typed/fx

RefSubject.compact

Converts a Computed or Filtered of Option<A> into a Filtered<A>, filtering out None values.

Package version
2.0.0-beta.13
Category
Optional queries
Since
1.0.0
Member of
RefSubject

Import

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

Access RefSubject.compact through the imported RefSubject 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 const compact: {
    <A, E, R>(ref: Computed<Option.Option<A>, E, R>): Filtered<A, E, R>;
    <A, E, R>(ref: Filtered<Option.Option<A>, E, R>): Filtered<A, E, R>;
    <R0, E0, A, E, R, E2, R2>(versioned: Versioned.Versioned<R0, E0, Option.Option<A>, E, R, Option.Option<A>, E2, R2>): Filtered<A, E0 | E | Exclude<E, Cause.NoSuchElementError> | Exclude<E2, Cause.NoSuchElementError>, R0 | R2 | Exclude<R, Scope.Scope>>;
};

Why

Converts a Computed or Filtered of Option<A> into a Filtered<A>, filtering out None values. Current reads and pushed versions use the same derivation, preventing snapshot and subscription behavior from diverging.

Ownership and lifetime

The compact view retains no independent value. Its Effect read fails with NoSuchElement while absent; the observing Scope owns and finalizes its Fx subscription.

Examples

import { Effect, Option } from "effect"
import * as RefSubject from "@typed/fx/RefSubject"

const program = Effect.gen(function* () {
  const maybeValue = yield* RefSubject.make(Option.some(42))

  // Compact the Option
  const filtered = RefSubject.compact(maybeValue)

  const value = yield* filtered
  console.log(value) // 42

  // If the Option becomes None, the Filtered will fail
  yield* RefSubject.set(maybeValue, Option.none())
  // yield* filtered would fail with NoSuchElementError
})

Other public imports

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

Source