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.
Processing cost: The get-or-create operation uses native Map membership and
lookup, and calls the factory only for an absent key; its dominant extra cost
is the caller factory.
Reuse: Stored values, including promises and undefined, are reused while the
supplied Map retains the key. The caller must key every relevant dependency
and remove stale or rejected entries; this helper cannot establish
external-data freshness or prevent reentrant factory calls.
Resource ownership: New values are transferred into the caller-owned Map,
whose growth and eviction remain the caller responsibility; the helper
acquires no external handle or background task.
// Subsequent calls return cached value without re-creating constsameObj = MapUtil.take(cache, "key1", () =>newExpensiveObject()); console.log(obj === sameObj); // true
Evidence
contracts/common.md#principled-implementation The namespace offers the get-or-create pattern over the native Map, whose has distinguishes an absent key from a stored undefined.
Evidence
contracts/common.md#clear-and-simple-design One function, without options or state.
Evidence
contracts/common.md#prohibited-implementation-shortcuts It uses only the public Map methods.
Evidence
contracts/common.md#meaningful-documentation The comment states the lazy initialization pattern with an example.
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.
Processing cost: The get-or-create operation uses native Map membership and lookup, and calls the factory only for an absent key; its dominant extra cost is the caller factory.
Reuse: Stored values, including promises and undefined, are reused while the supplied Map retains the key. The caller must key every relevant dependency and remove stale or rejected entries; this helper cannot establish external-data freshness or prevent reentrant factory calls.
Resource ownership: New values are transferred into the caller-owned Map, whose growth and eviction remain the caller responsibility; the helper acquires no external handle or background task.
Author
Jeongho Nam - https://github.com/samchon
Example
Evidence
contracts/common.md#principled-implementation The namespace offers the get-or-create pattern over the native
Map, whosehasdistinguishes an absent key from a storedundefined.Evidence
contracts/common.md#clear-and-simple-design One function, without options or state.
Evidence
contracts/common.md#prohibited-implementation-shortcuts It uses only the public Map methods.
Evidence
contracts/common.md#meaningful-documentation The comment states the lazy initialization pattern with an example.