function / @typed/fx

RefSubject.fromOption

Creates a RefSubject from an Option value.

Package version
2.0.0-beta.13
Category
Source adapters
Since
1.0.0
Member of
RefSubject

Import

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

Access RefSubject.fromOption 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 function fromOption<A>(option: Option.Option<A>, options?: RefSubjectOptions<Option.Option<A>>): Effect.Effect<RefSubject<Option.Option<A>>, never, Scope.Scope>;

Why

Stores the Option itself in writable state. None is an ordinary current value and does not add NoSuchElementError; callers opt into absence semantics with compact, or a fallback with getOrElse.

Ownership and lifetime

Construction requires Scope because it delegates to make, but the supplied Option needs no services and cannot fail. The returned RefSubject owns and publishes subsequent Option writes.

Examples

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

const program = Effect.gen(function* () {
  const ref = yield* RefSubject.fromOption(Option.some(42))
  const value = yield* ref
  console.log(Option.isSome(value)) // true
})

Other public imports

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

Source