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) {
  if (_val != null) {
    return Ok(_val!);
  }
  final result = f();
  if (result.isOk()) {
    _val = result.unwrap();
    return Ok(_val!);
  }
  return result;
}