Installing

dependencies:
  memoized:
import 'package:memoized/memoized.dart';

Usage

  • Basic

    Iterable<int> numbers = 1.to(30000000);
    final calculateSum = (() => numbers.sum()).memo;
    
    print(time(calculateSum));
    print(time(calculateSum));  // It returns the memoized value.
    
  • Update

    Iterable<int> numbers = 1.to(30000000);
    final calculateSum = (() => numbers.sum()).memo;
    
    numbers = 1.to(9043483);
    calculateSum.update();  // recomputed
    
  • Lazy Update

    Iterable<int> numbers = 1.to(30000000);
    final calculateSum = (() => numbers.sum()).memo;
    print(calculateSum());
    
    numbers = 1.to(9043483);
    calculateSum.requestUpdate();  // not computed
    
    numbers = 1.to(45000000);
    calculateSum.requestUpdate();  // not computed
    
    final value = calculateSum()   // recomputed at this point.
    

Libraries

memoized
typedef