getOrPut method

FutureOr<V> getOrPut(
  1. K key,
  2. FutureOr<V> factory(
    1. K id
    )
)

Implementation

FutureOr<V> getOrPut(K key, FutureOr<V> factory(K id)) {
  final existing = this[key];
  if (existing != null) return existing;

  final newInstance = factory(key) ?? nullPointer<V>("Factory produced null value");
  return newInstance.thenOr((resolved) {
    // After resolved, add to this map
    this.push(key, resolved);
    return resolved;
  });
}