Adds items to a map only if their key doesn't already exist
Uses provided Util.ToString function to create keys for items. Item is only added if it doesn't already exist. Thus the older item wins out, versus normal Map.set where the newest wins.
Map.set
import { Maps } from "https://unpkg.com/ixfx/dist/collections.js";const map = new Map();const peopleArray = [ _some people objects..._];Maps.addKeepingExisting(map, p => p.name, ...peopleArray); Copy
import { Maps } from "https://unpkg.com/ixfx/dist/collections.js";const map = new Map();const peopleArray = [ _some people objects..._];Maps.addKeepingExisting(map, p => p.name, ...peopleArray);
Rest
Adds items to a map only if their key doesn't already exist
Uses provided Util.ToString function to create keys for items. Item is only added if it doesn't already exist. Thus the older item wins out, versus normal
Map.set
where the newest wins.Example