Keyword.get_lazy
You're seeing just the function
get_lazy
, go back to Keyword module for more information.
Specs
Gets the value for a specific key
.
If key
does not exist, lazily evaluates fun
and returns its result.
This is useful if the default value is very expensive to calculate or generally difficult to setup and teardown again.
If duplicated entries exist, the first one is returned.
Use get_values/2
to retrieve all entries.
Examples
iex> keyword = [a: 1]
iex> fun = fn ->
...> # some expensive operation here
...> 13
...> end
iex> Keyword.get_lazy(keyword, :a, fun)
1
iex> Keyword.get_lazy(keyword, :b, fun)
13