memoize 2.0.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 92

Memoize

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

Warning

memoize_dart now supports dart2 since 2.0.0 version.

For 2.0.0 we drop func as dependency. Because it archived and doesn't support dart2.

If you need dart-1.24.3 use 1.4.0 version

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

2.0.0

  • Bump dependencies to support dart2, drop "func" dependency

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: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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
2.0.0 Aug 27, 2018 Go to the documentation of memoize 2.0.0 Download memoize 2.0.0 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]
87
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:memoize/memoize.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use memoize.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
Dev dependencies
test ^1.0.0