Skip to content

Commit de9fc8a

Browse files
yoshielpil
authored andcommitted
make it more clear that transient updates destroy the old value
1 parent 14dd3ab commit de9fc8a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/dict.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export function make() {
301301
export function from(iterable) {
302302
let transient = toTransient(emptyDict);
303303
for (const [key, value] of iterable) {
304-
transient = transientInsert(key, value, transient);
304+
transient = destructiveTransientInsert(key, value, transient);
305305
}
306306
return fromTransient(transient);
307307
}
@@ -448,7 +448,7 @@ export function insert(dict, key, value) {
448448
*
449449
* Returns a new transient.
450450
*/
451-
export function transientInsert(key, value, transient) {
451+
export function destructiveTransientInsert(key, value, transient) {
452452
const hash = getHash(key);
453453
transient.root = doInsert(transient, transient.root, key, value, hash, 0);
454454
return transient;
@@ -460,7 +460,7 @@ export function transientInsert(key, value, transient) {
460460
*
461461
* Returns a new transient.
462462
*/
463-
export function transientUpdateWith(key, fun, value, transient) {
463+
export function destructiveTransientUpdateWith(key, fun, value, transient) {
464464
const hash = getHash(key);
465465

466466
const existing = lookup(transient.root, key, hash);
@@ -553,7 +553,7 @@ function doInsert(transient, node, key, value, hash, shift) {
553553
* Consume a transient, removing a key if it exists.
554554
* Returns a new transient.
555555
*/
556-
export function transientDelete(key, transient) {
556+
export function destructiveTransientDelete(key, transient) {
557557
transient.root = doDelete(transient, transient.root, key, getHash(key), 0);
558558
return transient;
559559
}

src/gleam/dict.gleam

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn insert(into dict: Dict(k, v), for key: k, insert value: v) -> Dict(k, v)
195195
fn do_insert(key: k, value: v, dict: Dict(k, v)) -> Dict(k, v)
196196

197197
@external(erlang, "maps", "put")
198-
@external(javascript, "../dict.mjs", "transientInsert")
198+
@external(javascript, "../dict.mjs", "destructiveTransientInsert")
199199
fn transient_insert(
200200
key: k,
201201
value: v,
@@ -373,7 +373,7 @@ pub fn delete(from dict: Dict(k, v), delete key: k) -> Dict(k, v) {
373373
}
374374

375375
@external(erlang, "maps", "remove")
376-
@external(javascript, "../dict.mjs", "transientDelete")
376+
@external(javascript, "../dict.mjs", "destructiveTransientDelete")
377377
fn transient_delete(a: k, b: TransientDict(k, v)) -> TransientDict(k, v)
378378

379379
/// Creates a new dict from a given dict with all the same entries except any with
@@ -558,7 +558,7 @@ fn do_combine(
558558
}
559559

560560
@external(erlang, "maps", "update_with")
561-
@external(javascript, "../dict.mjs", "transientUpdateWith")
561+
@external(javascript, "../dict.mjs", "destructiveTransientUpdateWith")
562562
fn transient_update_with(
563563
key: k,
564564
fun: fn(v) -> v,

0 commit comments

Comments
 (0)