lazy_memo
2.0.1, released 5 weeks ago by simphotonics.com
Cached lazy variables and memoized functions for Dart.
What it does
Provides classes for defining lazy variables that can be marked for re-initialization, collection-backed lazy types (List, Set, Map), and memoized functions that cache calculation results based on input arguments.
AI-written summary of version 2.0.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to store and reuse the result of costly computations in Dart.
- You want memoized functions that store and recall the result of function calls with high computational cost.
- You need lazy variables that can be selectively invalidated and re-initialized.
Skip it when
- You just need standard lazy initialization once, which is fully covered by Dart's built-in late modifier.
- You are dealing with trivial computations where caching overhead outweighs recalculation costs.
Strengths
- Supports cache invalidation and re-initialization for lazy variables.
- Includes specialized collection wrappers like LazyList, LazySet, and LazyMap.
- Provides memoized function builders to avoid repeated expensive calculations.
Weaknesses
- Memoization comes at the cost of additional indirections and higher memory usage.
- Requires manual maintenance of function tables or cache states.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Add lazy_memo to pubspec.yaml dependencies.
import 'package:lazy_memo/lazy_memo.dart';
double objectFactory() {
return 42.0;
}
late final a = Lazy(objectFactory);
var value = a();Alternatives
Packages that do the same job and could replace lazy_memo.
- memoize
Returns cached result of function call when inputs were not changed from previous invocation.
50Compare - schedulers
Dart library for running asynchronous functions on time with interval, rate, parallel, and lazy controls.
48Compare
Works with
Packages commonly used together with lazy_memo: ones it builds on, ones built on it, and its own family.