function / @typed/fx/RefSubject

reset

Resets a RefSubject to its initial value, returning the previous value if it existed.

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

Import

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

Signatures

export declare function reset<A, E, R>(ref: RefSubject<A, E, R>): Effect.Effect<Option.Option<A>, E, R>;

Why

Resets a RefSubject to its initial value, returning the previous value if it existed. The transition is serialized at the RefSubject rather than coordinated by callers or UI components.

Ownership and lifetime

Running reset 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, Option } from "effect"
import * as RefSubject from "@typed/fx/RefSubject"

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

  yield* RefSubject.set(count, 5)
  const before = yield* count
  console.log(before) // 5

  // Reset to initial value
  const previous = yield* RefSubject.reset(count)
  console.log(Option.isSome(previous)) // true
  console.log(previous.value) // 5

  const after = yield* count
  console.log(after) // 0
})

Other public imports

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

Source