You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Allow inserting a new value, or updating an existing one
124
-
* @throws if called for a key with no current value and no `insert` handler is provided
125
-
* @returns current value in map (after insertion/updating)
126
-
* ```ts
127
-
* // return current value if already in map, otherwise initialise to 0 and return that
128
-
* const num = emplace(map, key, {
129
-
* insert: () => 0
130
-
* })
131
-
*
132
-
* // increase current value by one if already in map, otherwise initialise to 0
133
-
* const num = emplace(map, key, {
134
-
* update: (n) => n + 1,
135
-
* insert: () => 0,
136
-
* })
137
-
*
138
-
* // only update if value's already in the map - and increase it by one
139
-
* if (map.has(key)) {
140
-
* const num = emplace(map, key, {
141
-
* update: (n) => n + 1,
142
-
* })
143
-
* }
144
-
* ```
145
-
*
146
-
* @remarks
147
-
* Based on https://github.com/tc39/proposal-upsert currently in Stage 2 - maybe in a few years we'll be able to replace this with direct method calls
0 commit comments