function / @typed/fx/RefSubject

fromFx

Creates a RefSubject from an Fx, tracking the latest emitted value.

Package version
2.0.0-beta.7
Category
Source adapters
Since
1.0.0

Import

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

Signatures

export declare function fromFx<A, E, R>(fx: Fx<A, E, R>, options?: RefSubjectOptions<A>): Effect.Effect<RefSubject<A, E>, never, R | Scope.Scope>;

Why

Makes fx acquisition explicit while normalizing it into current RefSubject state and subsequent pushed versions.

Ownership and lifetime

The creation Effect requires Scope. It owns initializer acquisition, live source subscriptions, and cleanup; source failures and services stay on reads and pushes.

Examples

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

const program = Effect.gen(function* () {
  // Create an Fx that emits multiple values
  const numbers = Fx.fromIterable([1, 2, 3, 4, 5])

  // Create a RefSubject that tracks the latest value
  const ref = yield* RefSubject.fromFx(numbers)

  // Get the latest value
  const latest = yield* ref
  console.log(latest) // 5
})

Other public imports

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

Source