A namespace providing utility functions for Map manipulation.
This namespace contains helper functions for working with JavaScript Map objects, providing convenient methods for common Map operations like retrieving values with lazy initialization.
Jeongho Nam - https://github.com/samchon
// Create a cache with lazy initialization const cache = new Map<string, ExpensiveObject>(); const obj = MapUtil.take(cache, "key1", () => { console.log("Creating expensive object..."); return new ExpensiveObject(); }); // Subsequent calls return cached value without re-creating const sameObj = MapUtil.take(cache, "key1", () => new ExpensiveObject()); console.log(obj === sameObj); // true Copy
// Create a cache with lazy initialization const cache = new Map<string, ExpensiveObject>(); const obj = MapUtil.take(cache, "key1", () => { console.log("Creating expensive object..."); return new ExpensiveObject(); }); // Subsequent calls return cached value without re-creating const sameObj = MapUtil.take(cache, "key1", () => new ExpensiveObject()); console.log(obj === sameObj); // true
A namespace providing utility functions for Map manipulation.
This namespace contains helper functions for working with JavaScript Map objects, providing convenient methods for common Map operations like retrieving values with lazy initialization.
Author
Jeongho Nam - https://github.com/samchon
Example