effect-io-ai

Package: effect
Module: Struct

Struct.evolveEntries

Transforms both keys and values of a struct selectively. Each per-key function receives (key, value) and must return a [newKey, newValue] tuple. Keys without a corresponding function are copied unchanged.

When to use

Use when you need to rename a key and change its value in one step.

Details

The return type is fully tracked at the type level.

Example (Transforming keys and values together)

import { pipe, Struct } from "effect"

const result = pipe(
  { amount: 100, label: "total" },
  Struct.evolveEntries({
    amount: (k, v) => [`${k}Cents`, v * 100],
    label: (k, v) => [k, v.toUpperCase()]
  })
)
console.log(result) // { amountCents: 10000, label: "TOTAL" }

See

Signature

declare const evolveEntries: { <S extends object, E extends EntryEvolver<S>>(e: E): (self: S) => EntryEvolved<S, E>; <S extends object, E extends EntryEvolver<S>>(self: S, e: E): EntryEvolved<S, E>; }

Source

Since v4.0.0