variable / @typed/fx/RefStruct

get

Get a property value from the current state of a RefStruct.

Package version
2.0.0-beta.7
Category
Derived queries
Since
1.18.0

Import

import { get } from "@typed/fx/RefStruct";

Signatures

export declare const get: {
    <S extends object, const K extends keyof S>(key: K): <E, R>(ref: RefStruct<S, E, R>) => RefSubject.Computed<S[K], E, R>;
    <S extends object, const K extends keyof S, E, R>(ref: RefStruct<S, E, R>, key: K): RefSubject.Computed<S[K], E, R>;
};

Why

Projects a known property as Computed state, so current reads and future pushes stay linked to the struct without copying that field into a second store.

Ownership and lifetime

The get view retains no independent state. An Effect read samples the source once; Fx observation follows later pushes and its observing Scope owns subscription cleanup.

Examples

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

const program = Effect.scoped(Effect.gen(function* () {
  const account = yield* RefStruct.make({ name: "Ada", active: true })
  const name = RefStruct.get(account, "name")
  return yield* name
}))

Other public imports

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

Source