memoize<T> function
A function that returns a memoized version of the provided Computed instance.
The memoized version will cache the last cacheSize unique computed values and their
corresponding source values. When the sources change to previously seen values,
the cached result will be returned instead of recomputing.
final count = Reactive(0);
final expensive = Computed([count], (sources) {
// Expensive computation
return sources[0].value * 100;
});
// Create a memoized version with a cache size of 5
final memoizedExpensive = memoize(expensive, cacheSize: 5);
Implementation
Computed<T> memoize<T>(Computed<T> computed, {int cacheSize = 1}) {
return _MemoizedComputed<T>(computed, cacheSize: cacheSize);
}