function / @typed/fx

RefSubject.delete

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

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

Import

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

Access RefSubject.delete 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 { reset as delete };
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