interface / @typed/fx

RefSubject.Computed

A Computed is a read-only view of a value that can change over time. It is an Fx that emits the current value and subsequent updates. It is also an Effect that samples the current value.

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

Import

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

Access RefSubject.Computed 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 Computed<out A, out E = never, out R = never> extends Versioned.Versioned<R, E, A, E, R | Scope.Scope, A, E, R> {
    readonly [ComputedTypeId]: ComputedTypeId;
}
export declare namespace Computed {
    type Any = Computed<any, any, any> | Computed<never, any, any> | Computed<any, never, any> | Computed<never, never, any>;
}

Why

Represents derived state as both an Effectful current read and an Fx of subsequent versions, without granting write access.

Ownership and lifetime

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

Property: [[computed:[ComputedTypeId]]]

Carries the runtime marker recognized by isComputed.

Property: [[computed:[ComputedTypeId]]]: Why

Marks the value as Computed for runtime guards and composition without granting writable RefSubject operations.

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

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

Examples

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

// Create a RefSubject and derive a Computed from it
const program = Effect.gen(function* () {
  const count = yield* RefSubject.make(0)

  // Create a computed that doubles the count
  const doubled = RefSubject.map(count, (n) => n * 2)

  // Sample the computed value
  const value = yield* doubled
  console.log(value) // 0

  // Update the source
  yield* RefSubject.set(count, 5)

  // The computed automatically reflects the change
  const newValue = yield* doubled
  console.log(newValue) // 10
})

Members

Other public imports

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

Source