Keyword.put_new_lazy/3

defmodule Keyword do
  def put_new_lazy(keywords, key, fun)
end

Evaluates fun and puts the result under key in keywords 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 keywords doesn’t contain key then it’s added using the value returned from fun.