compute method

R compute(
  1. T value
)

Computes and caches value.

Implementation

R compute(T value) {
  var key = generateKey(value);

  var prev = _cache[key];
  // A cached `null` result is told apart from a cache miss by `containsKey`:
  if (prev != null || _cache.containsKey(key)) return prev as R;

  ++_computationCount;
  var result = function(value);

  _cache[key] = result;
  return result;
}