• Queries the map for the given key and returns its associated value, if it is present.

    If the key is absent, then the producer will be invoked. The computed value will be associated with the given key and returned.

    Example

    export function lazyLookup<K, V>(
    producer: (key: K) => V,
    cache: PickMap<K, V, 'has' | 'set' | 'get'> = new Map()
    ) {
    return (key: K): V => computeIfAbsent(cache, key, producer);
    }

    Type Parameters

    Type Parameters

    • K

    • V

    Parameters

    • map: PickMap<K, V, "get" | "has" | "set">

      the map to work with

    • key: K

      the queried key

    • producer: ((key: K) => V)

      a function to create a value if the key is not present

        • (key: K): V
        • Parameters

          • key: K

          Returns V

    Returns V

Generated using TypeDoc