interface / @typed/fx

RefSubject.Filtered

A Filtered is a Computed that may not always have a value. It is essentially a Computed<Option<A>> with helper methods.

Package version
2.0.0-beta.13
Category
Read-only state
Since
1.0.0
Member of
RefSubject

Import

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

Access RefSubject.Filtered 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 interface Filtered<out A, out E = never, out R = never> extends Versioned.Versioned<R, E, A, E, R | Scope.Scope, A, E | Cause.NoSuchElementError, R> {
    readonly [FilteredTypeId]: FilteredTypeId;
    asComputed(): Computed<Option.Option<A>, E, R>;
}
export declare namespace Filtered {
    type Any = Filtered<any, any, any> | Filtered<never, any, any> | Filtered<any, never, any> | Filtered<never, never, any>;
}

Why

Represents a derived value that may be absent now and become available on a later push, preserving absence in the state contract.

Ownership and lifetime

Filtered is a contract and performs no acquisition. Implementations retain the errors, services, interruption, and Scope requirements expressed by its members.

Property: [[computed:[FilteredTypeId]]]

Carries the runtime marker distinguishing conditional Filtered state from Computed state.

Property: [[computed:[FilteredTypeId]]]: Why

Marks the value as Filtered for runtime guards and composition without changing its data or error channels.

Property: [[computed:[FilteredTypeId]]]: Ownership and lifetime

This declaration performs no acquisition and retains no resources. Implementations preserve source errors, services, and lifetime.

Method: asComputed

Converts the Filtered back to a Computed of Option.

Method: asComputed: Why

Converts the Filtered back to a Computed of Option. The result remains a lazy view rather than a duplicated mutable value.

Method: asComputed: Ownership and lifetime

The as computed view retains no independent state. Effectful reads sample the source once; Fx observation follows later pushes and the observing Scope finalizes it.

Examples

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

// Create a RefSubject and filter it
const program = Effect.gen(function* () {
  const numbers = yield* RefSubject.make([1, 2, 3, 4, 5])

  // Get the first even number (filtered)
  const firstEven = RefSubject.filterMap(
    numbers,
    (arr) => Option.fromNullable(arr.find((n) => n % 2 === 0))
  )

  // Try to get the value (may fail with NoSuchElementError)
  const value = yield* firstEven
  console.log(value) // 2

  // Or convert back to Option
  const option = firstEven.asComputed()
  const maybeValue = yield* option
  console.log(Option.isSome(maybeValue)) // true
})
import { Effect, Option } from "effect"
import * as RefSubject from "@typed/fx/RefSubject"

const program = Effect.gen(function* () {
  const filtered = RefSubject.filterMap(
    yield* RefSubject.make([1, 2, 3]),
    (arr) => Option.fromNullable(arr.find((n) => n > 5))
  )

  // Convert to Computed<Option<number>>
  const computed = filtered.asComputed()
  const option = yield* computed
  console.log(Option.isNone(option)) // true (no number > 5)
})

Members

Other public imports

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

Source