A map where calling .get() will add a value to the map before returning it, if it does not yet exist.
.get()
const tallies = new MagicalMap<string, number>(() => 0);tallies.get('joe'); // 0tallies.set('fred', tallies.get('fred') + 1);tallies.get('fred'); // 1 Copy
const tallies = new MagicalMap<string, number>(() => 0);tallies.get('joe'); // 0tallies.set('fred', tallies.get('fred') + 1);tallies.get('fred'); // 1
called when trying to get() for a key that is not yet in the map. The return value of createNewValue will be set into the map, then returned.
get()
createNewValue
A map where calling
.get()will add a value to the map before returning it, if it does not yet exist.