replace

@Nullable
open fun replace(@NotNull key: @NotNull K, @NotNull function: @NotNull (V) -> V): @Nullable V

Replaces the entry for the specified key only if it is currently mapped to some value. Preserves its priority and insertion order. A null result removes the mapping.

Return

the previous value, or null if there was no mapping for the key

Parameters

key

key with which the specified value is associated

function

function to compute the value

Throws

if the key is null, or the function is null for an existing key

if the function structurally modifies this map