Map.get_lazy

You're seeing just the function get_lazy, go back to Map module for more information.

Specs

get_lazy(map(), key(), (() -> value())) :: value()

Gets the value for a specific key in map.

If key is present in map then its value value is returned. Otherwise, fun is evaluated and its result is returned.

This is useful if the default value is very expensive to calculate or generally difficult to setup and teardown again.

Examples

iex> map = %{a: 1}
iex> fun = fn ->
...>   # some expensive operation here
...>   13
...> end
iex> Map.get_lazy(map, :a, fun)
1
iex> Map.get_lazy(map, :b, fun)
13