Map.put_new_lazy/3
defmodule Map do
def put_new_lazy(map, key, fun)
end
Evaluates fun
and puts the result under key
in map
unless key
is already present.
This function is useful in case you want to compute the value to put under key
only if key
is not already present, as for example, when the value is expensive to calculate or generally difficult to setup and teardown again.
If map
doesn’t contain key
then it’s added using the value returned from fun
.