A.OrdMap.put_new_lazy
You're seeing just the function
put_new_lazy
, go back to A.OrdMap module for more information.
Specs
Evaluates fun
and puts the result under key
in ord_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.
Examples
iex> ord_map = A.OrdMap.new(b: "Bat", c: "Cat")
iex> expensive_fun = fn -> "Ant" end
iex> A.OrdMap.put_new_lazy(ord_map, :a, expensive_fun)
ord(%{b: "Bat", c: "Cat", a: "Ant"})
iex> A.OrdMap.put_new_lazy(ord_map, :b, expensive_fun)
ord(%{b: "Bat", c: "Cat"})