memo0<R> function

Func0<R> memo0<R>(
  1. Func0<R> func
)

Lazy evaluates function and returns cached result on each call.

Implementation

Func0<R> memo0<R>(Func0<R> func) {
  late R prevResult;
  bool isInitial = true;

  return (() {
    if (!isInitial) {
      return prevResult;
    } else {
      prevResult = func();
      isInitial = false;

      return prevResult;
    }
  });
}