Function computeIfAbsent

  • Mutation

    Remark

    only returns undefined if mappingFunction returns undefined

    Example

    Set a Map entry if the key is absent

    const map = new Map();
    computeIfAbsent(map)(1, key => key + 1);
    console.log(map); // Map([[1, 2]])

    Type Parameters

    • K

      the Map key type

    • V

      the Map value type

    Parameters

    • map: Map<K, V>

      the Map to set the entry

    Returns ((key: K, mappingFunction: Mapper<K, V>) => undefined | V)

      • (key: K, mappingFunction: Mapper<K, V>): undefined | V
      • Parameters

        • key: K
        • mappingFunction: Mapper<K, V>

        Returns undefined | V

Generated using TypeDoc