extractAndPutIfPresent

fun MutableMap<String, Any?>.extractAndPutIfPresent(key: String, data: Map<String, Any?>, ifPresent: (Any) -> Any = { it })

Copies the value at key from data into this mutable map under the same key, applying ifPresent to it first — but only when key is present in data and non-null. A no-op otherwise, leaving this map's own entry (if any) untouched.

Parameters

key

the key to copy.

data

the source map to read from.

ifPresent

transform applied to the value before storing it. Identity by default.