memoize 1.4.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 43

Memoize

memoize returns cached result of function call when inputs were not changed from previous invocation.

Examples

memo1, memo2, ... memo10 compare arguments with == operator:

import 'dart:math';
import 'package:memoize/memoize.dart';

void main() {
  var rect1 = new Rectangle<int>(0, 0, 10, 10);
  var rect2 = new Rectangle<int>(0, 0, 10, 10);
  
  var func = memo1((Rectangle<int> a) => a.width * a.height);

  print(func(rect1));
  print(func(rect2)); // cached result is returned
}

imemo1, imemo2, ... imemo10 compare arguments with identical function:

import 'dart:math';
import 'package:memoize/memoize.dart';

void main() {
  var rect1 = new Rectangle<int>(0, 0, 10, 10);
  var rect2 = new Rectangle<int>(0, 0, 10, 10);
  
  var func = imemo1((Rectangle<int> a) => a.width * a.height);

  print(func(rect1));
  print(func(rect1)); // cached - same object instance
  print(func(rect2)); // not cached - different object instance
}

memo0 caches result on first call and can be used as lazy cache:

import 'dart:math';
import 'package:memoize/memoize.dart';

void main() {
  var func = memo0(() => new Rectangle<int>(0, 0, 10, 10));
  
  print(func());
  print(func()); // cached - same object instance
}

Contributors

Changelog

1.4.0

  • Add 0 argument implementation

1.3.0

  • Add 5-10 arguments implementation

1.2.0

  • Add 4 arguments implementation

1.1.0

  • Add 3 arguments implementation

1.0.0

  • Add 1 and 2 arguments implementation

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  memoize: ^1.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:memoize/memoize.dart';
  
Version Uploaded Documentation Archive
1.4.0 Feb 21, 2018 Go to the documentation of memoize 1.4.0 Download memoize 1.4.0 archive
1.3.0 Sep 6, 2017 Go to the documentation of memoize 1.3.0 Download memoize 1.3.0 archive
1.2.0 Apr 24, 2017 Go to the documentation of memoize 1.2.0 Download memoize 1.2.0 archive
1.1.0 Mar 24, 2017 Go to the documentation of memoize 1.1.0 Download memoize 1.1.0 archive
1.0.0 Mar 15, 2017 Go to the documentation of memoize 1.0.0 Download memoize 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
86
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
43
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0 <2.0.0