Memo<T, A> class

A class callable that is used for memoizing values(T) returned by a calcutate function(calculateValue).

This is a factorial example:

late final factorial = Memo(calculateFactorial);

BigInt calculateFactorial(Args<int> args) {
  final numero = args.arg;
  if (numero == 0) return BigInt.one;
  return BigInt.from(numero) * factorial(Args(numero - 1));
}

void main() {
  // Returns the result of multiplication of 1 to 50.
  final f50 = factorial(const Args(50));
  // Returns the result immediately from cache
  // because it was resolved in the previous line.
  final f10 = factorial(const Args(10));
  // Returns the result of the multiplication of 51 to 100
  // and 50! which is obtained from the cache.
  final f100 = factorial(const Args(100));

  print(
    'Results:\n'
    '\t10!: $f10\n'
    '\t50!: $f50\n'
    '\t100!: $f100\n'
  );
}

Constructors

Memo(FunctionArg<T, A> computeValue, [MemoInterceptor<T, A>? interceptor])
A class callable that is used for memoizing values(T) returned by a calcutate function(calculateValue).

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(A arg, {bool overrideCache = false}) → T
Invokes the calculateValue with the given arg, then stores and returns the resolved value.
clear() → void
Removes all cached data.
get(A arg) → T?
Returns the cached value by arg.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(A arg) → T?
Removes the cached value by arg.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

inline<T, A>(FunctionArg<T, A> computeValue, [MemoInterceptor<T, A>? interceptor]) FunctionMemo<T, A>
Creates a memoized function version. It´s used for memoizing values(T) returned by a calcutate function(computeValue).