variable / @typed/fx/RefSubject

set

Sets the value of a RefSubject.

Package version
2.0.0-beta.7
Category
State updates
Since
1.0.0

Import

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

Signatures

export declare const set: {
    <A>(value: A): <E, R>(ref: RefSubject<A, E, R>) => Effect.Effect<A, E, R>;
    <A, E, R>(ref: RefSubject<A, E, R>, a: A): Effect.Effect<A, E, R>;
};

Why

Sets the value of a RefSubject. The transition is serialized at the RefSubject rather than coordinated by callers or UI components.

Ownership and lifetime

Running set performs one serialized subject transition and resolves with its committed value. It acquires no resource; failures and services remain those of the source ref.

Examples

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

const program = Effect.gen(function* () {
  const count = yield* RefSubject.make(0)

  // Set the value
  yield* RefSubject.set(count, 10)
  const value = yield* count
  console.log(value) // 10

  // Can also use pipe syntax
  yield* count.pipe(RefSubject.set(20))
  const newValue = yield* count
  console.log(newValue) // 20
})

Other public imports

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

Source