Wraps a factory in a keyed accessor that computes the value for a key on the first request and reuses the result
thereafter, so work the caller may never need is neither done upfront nor repeated. All callers requesting the same
key share the same value, and a value of undefined is kept and reused like any other.
Keys are compared as Map compares them, with SameValueZero equality: NaN matches NaN and 0
matches -0. Object keys match by identity, so equal but distinct objects get separate values from the factory.
Warning
Values are kept for the lifetime of the accessor and never evicted. Memory use grows with every distinct key
requested, so the accessor is suited to key sets known to stay small or bounded over the accessor's lifetime.
Important
A factory call that throws is not kept, and the next request for that key calls the factory again. A rejected
promise is a value like any other: it is kept, and every later request for its key gets the same rejection.
Defers keyed values to first use.
Wraps a factory in a keyed accessor that computes the value for a key on the first request and reuses the result thereafter, so work the caller may never need is neither done upfront nor repeated. All callers requesting the same key share the same value, and a value of
undefinedis kept and reused like any other.Keys are compared as Map compares them, with SameValueZero equality:
NaNmatchesNaNand0matches-0. Object keys match by identity, so equal but distinct objects get separate values from the factory.Values are kept for the lifetime of the accessor and never evicted. Memory use grows with every distinct key requested, so the accessor is suited to key sets known to stay small or bounded over the accessor's lifetime.
A factory call that throws is not kept, and the next request for that key calls the factory again. A rejected promise is a value like any other: it is kept, and every later request for its key gets the same rejection.