For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/object/evolve.md.

evolve

Applies a spec of transformation functions to matching keys of an object, returning a new object. Keys not in the spec are copied as-is.

evolve({ name: '  Alice  ', age: 29, role: 'admin' }, {
  name: (s) => s.trim(),
  age: (n) => n + 1,
})
// { name: 'Alice', age: 30, role: 'admin' }

Usage

evolve<T extends Record<string, unknown>>(obj: T, spec: { [K in keyof T]?: (value: T[K]) => T[K] })

Applies a spec of transformation functions to matching keys of an object, returning a new object. Keys not in the spec are copied as-is.

import { evolve } from 'massaman'
// or:  import { evolve } from 'massaman/object'

evolve({ name: '  Alice  ', age: 29, role: 'admin' }, {
  name: (s) => s.trim(),
  age: (n) => n + 1,
})
// { name: 'Alice', age: 30, role: 'admin' }

Parameters

objTrequired

the source object.

spec{ [K in keyof T]?: (value: T[K]) => T[K] }required

the transformations keyed by property name.

Returns

a new object with matching transformations applied and all other properties preserved.

T