Skip to main content
Module

x/upsert/emplace.ts>insert

Maps for emplace, TC39 proposal-upsert implementation
Latest
function insert
import { insert } from "https://deno.land/x/upsert@1.2.0/emplace.ts";

Add the entry if the key does not exist.

Examples

Example 1

import { insert } from "https://deno.land/x/upsert/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

declare const key: string;
declare const value: number;
const map = new Map<typeof key, typeof value>();

insert(map, key, () => value);

assertEquals(map, new Map([[key, value]]));

Type Parameters

K
V
optional
M = MapLike<K, V>

Parameters

map: Readonly<MapLike<K, V>> & M
key: K
callback: InsertCallback<K, V, M>