effect-io-ai

Package: effect
Module: Struct

Struct.evolve

Transforms values of a struct selectively using per-key functions. Keys without a corresponding function are copied unchanged.

When to use

Use when you want to update specific fields while keeping the rest intact.

Details

Each transform function receives the current value and returns the new value; the return type can differ from the input type.

Example (Transforming selected values)

import { pipe, Struct } from "effect"

const result = pipe(
  { name: "alice", age: 30, active: true },
  Struct.evolve({
    name: (s) => s.toUpperCase(),
    age: (n) => n + 1
  })
)
console.log(result) // { name: "ALICE", age: 31, active: true }

See

Signature

declare const evolve: { <S extends object, E extends Evolver<S>>(e: E): (self: S) => Evolved<S, E>; <S extends object, E extends Evolver<S>>(self: S, e: E): Evolved<S, E>; }

Source

Since v2.0.0