このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

evolve

Runs selected values through per-key transformation functions, leaving the rest of the Map as-is.

Map<K, Object?> evolve<K>( Map<K, Object? Function(Object? value)> transformations, Map<K, Object?> map)

Lecture

evolve takes a "recipe" map — key to transformation function — and a data map, and produces a new map where every key that appears in the recipe has its value passed through the matching function; every other key is copied through unchanged.

Notice the signature is deliberately loose: both maps are typed with Object? values, mirroring FxTS's dynamically-typed original. That means your transformation functions receive Object? and must cast (v as String, v as int, …) before doing anything type-specific — a small tax for the flexibility of applying different transformations to different value types within a single map. If you know the shape of your data ahead of time and don't need per-key heterogeneity, a plain {...map, 'key': f(map['key'])} spread is often more idiomatic Dart; reach for evolve when the recipe itself is data (e.g. built once and reused across many maps).

Demo 1 · Basics

Demo 2 · Parsing raw string fields

Try it yourself

Exercise: use evolve to double the 'price' field and leave 'title' untouched.

Related: prop — read a single value out · omitBy — drop entries instead of transforming them · compactObject — a specialized cleanup pass · resolveProps — the async cousin, awaiting instead of transforming