function / @typed/fx

RefSubject.decrement

Decrements a numeric RefSubject by 1.

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.decrement 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 decrement<E, R>(ref: RefSubject<number, E, R>): Effect.Effect<number, E, R>;

Why

Decrements a numeric RefSubject by 1. The transition is serialized at the RefSubject rather than coordinated by callers or UI components.

Ownership and lifetime

Running decrement 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(10)

  yield* RefSubject.decrement(count)
  const value = yield* count
  console.log(value) // 9

  yield* RefSubject.decrement(count)
  const newValue = yield* count
  console.log(newValue) // 8
})

Other public imports

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

Source