memoize 2.0.0

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(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)); // 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()); // 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:

  memoize: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter 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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21


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 filename patterns include main.dart, example.dart, and memoize.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.

Package is getting outdated. (-5.75 points)

The package was last published 55 weeks ago.


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