function setWithReturnValueIfNotSet(obj, key, f) {
  if (key in obj) {
    return obj[key];
  }

  const val = f();
  obj[key] = val;
  return val;
}
Sets a key and value to an object if the key is not set. The value will be
the return value of the given function. If the key already exists, the
object will not be changed and the function will not be called (the function
will be lazily evaluated -- only called if necessary).
This function is particularly useful when used with an `Object` which is
acting as a cache.
@param {?Object<K,V>} obj The object to which to add the key-value pair.
@param {string} key The key to add.
@param {function():V} f The value to add if the key wasn't present.
@return {V} The value of the entry at the end of the function.
@template K,V