Package: effect
Module: Struct
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
evolveKeys – transform keys instead of valuesevolveEntries – transform both keys and valuesmap – apply the same transformation to all valuesSignature
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>; }
Since v2.0.0