MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / getOrUpdate

Function getOrUpdate

src/utils.ts:52–62  ·  view source on GitHub ↗
(
    map: Map<K, V> | (K extends object ? WeakMap<K, V> : never),
    key: K,
    getDefaultValue: () => NoInfer<V>
)

Source from the content-addressed store, hash-verified

50type NoInfer<T> = [T][T extends any ? 0 : never];
51
52export function getOrUpdate<K, V>(
53 map: Map<K, V> | (K extends object ? WeakMap<K, V> : never),
54 key: K,
55 getDefaultValue: () => NoInfer<V>
56): V {
57 if (!map.has(key)) {
58 map.set(key, getDefaultValue());
59 }
60
61 return map.get(key)!;
62}
63
64export function isNonNull<T>(value: T | null | undefined): value is T {
65 return value != null;

Callers 4

readLuaLibFeatureFunction · 0.90
createVisitorMapFunction · 0.90
validateAssignmentFunction · 0.90

Calls 3

hasMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected