memoize 1.4.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 91

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

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or 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
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

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 21, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
81 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
91

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • Maintain an example.

    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 >=1.21.0 <2.0.0
func >=1.0.0 <2.0.0 1.0.0
Dev dependencies
test 0.12.24+2