getOrTryInit<E extends Object> method

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

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

Result<T, E> getOrTryInit<E extends Object>(Result<T, E> Function() f) {
  if (_isSet) {
    return Ok(_val as T);
  }
  final result = f();
  if (result.isOk()) {
    _val = result.unwrap();
    _isSet = true;
    return Ok(_val as T);
  }
  return result;
}