function / @typed/fx/RefSubject

struct

Combines multiple RefSubject, Computed, or Filtered instances into a single struct.

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

Import

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

Signatures

export declare function struct<const Refs extends Readonly<Record<string, RefSubject.Any | Computed.Any | Filtered.Any>>>(refs: Refs): StructFrom<Refs>;

Why

Combines several refs into one state value while preserving whether the result is writable, computed, or filtered from its inputs.

Ownership and lifetime

This declaration performs no acquisition and retains no resources. Implementations preserve source errors, services, and lifetime.

Examples

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

const program = Effect.gen(function* () {
  const firstName = yield* RefSubject.make("Alice")
  const lastName = yield* RefSubject.make("Smith")
  const age = yield* RefSubject.make(30)

  // Combine into a struct
  const person = RefSubject.struct({
    firstName,
    lastName,
    age
  })

  const fullPerson = yield* person
  console.log(fullPerson) // { firstName: "Alice", lastName: "Smith", age: 30 }

  // Update one field
  yield* RefSubject.set(firstName, "Bob")

  // Struct automatically updates
  const updated = yield* person
  console.log(updated.firstName) // "Bob"
})

Other public imports

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

Source