getOrTryInit<E extends Object> method

  1. @override
Result<T, E> getOrTryInit<E extends Object>(
  1. Result<T, E> f()
)
override

Gets the contents of the cell, initializing it with f if the cell was empty. If the cell was empty and f failed, an error is returned.

Implementation

@override
Result<T, E> getOrTryInit<E extends Object>(Result<T, E> Function() f) {
  var val = _cache[this] as T?;
  if (val != null) {
    return Ok(val);
  }
  final result = f();
  if (result.isOk()) {
    final val = result.unwrap();
    _cache[this] = val;
    return Ok(val);
  }
  return result;
}