ult is shallow-equal to the most recent mapped value.
 */
function memoizeResourceShallow(map) {
  const cache = new WeakMap();

  const fn = (input, identity, args) => {
    let existingEntry = cache.get(identity);

    if (!existingEntry || existingEntry.input !== input) {
      const mapper = map;
      const output = mapper(input, identity, args);

      if (existingEntry) {
        // If the new output is shallow-equal to the old output, we reuse
        // the previous object instead to preserve object equality.
        const newOutput = (0, _compare.shallowEqual)(output, existingEntry.output) ? existingEntry.output : output;
        existingEntry.output = newOutput;
        existingEntry.input = input;
      } else {
        existingEntry = {
          input,
          output
        };
        cache.set(identity, existingEntry);
      }
    }

    return existingEntry.output;
  };

  fn.needsArgs = map.needsArgs;
  return fn;
}PK