weak_map 2.1.0 copy "weak_map: ^2.1.0" to clipboard
weak_map: ^2.1.0 copied to clipboard

WeakMap is a map where the keys are weakly referenced. WeakContainer lets you check if an object is the same you had before. Cache functions for memoization with weak-references.

example/main.dart

import 'package:weak_map/weak_map.dart';

void main() {
  var map = WeakMap<String, int?>();

  print('\nmap["A"] = 1');
  map["A"] = 1;
  print('A = ${map["A"]}'); // A = 1
  print('A exists in map = ${map.contains("A")}'); // A = true

  print('\nDoes not set B');
  print('B = ${map["B"]}'); // B = null
  print('B exists in map = ${map.contains("B")}'); // A = false

  print('\nmap["A"] = null');
  map["A"] = null;
  print('A = ${map["A"]}'); // A = null
  print('A exists in map = ${map.contains("A")}'); // A = true

  print('\nvalue = WeakContainer("X")');
  var value = WeakContainer("X");
  print('Contains X = ${value.contains("X")}'); // Contains X = true
  print('Contains Y = ${value.contains("Y")}'); // Contains Y = false
}
16
likes
120
pub points
82%
popularity

Publisher

verified publisherglasberg.dev

WeakMap is a map where the keys are weakly referenced. WeakContainer lets you check if an object is the same you had before. Cache functions for memoization with weak-references.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-2-Clause (LICENSE)

More

Packages that depend on weak_map