Skip to content

Commit 14e839d

Browse files
committed
Rename in JS FFI
1 parent fe5d2c9 commit 14e839d

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/persistent-hash-map.mjs renamed to src/dict.mjs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -814,19 +814,19 @@ function forEach(root, fn) {
814814
}
815815
}
816816
/**
817-
* Extra wrapper to keep track of map size and clean up the API
817+
* Extra wrapper to keep track of Dict size and clean up the API
818818
* @template K,V
819819
*/
820-
export default class PMap {
820+
export default class Dict {
821821
/**
822822
* @template V
823823
* @param {Record<string,V>} o
824-
* @returns {PMap<string,V>}
824+
* @returns {Dict<string,V>}
825825
*/
826826
static fromObject(o) {
827827
const keys = Object.keys(o);
828-
/** @type PMap<string,V> */
829-
let m = PMap.new();
828+
/** @type Dict<string,V> */
829+
let m = Dict.new();
830830
for (let i = 0; i < keys.length; i++) {
831831
const k = keys[i];
832832
m = m.set(k, o[k]);
@@ -836,18 +836,18 @@ export default class PMap {
836836
/**
837837
* @template K,V
838838
* @param {Map<K,V>} o
839-
* @returns {PMap<K,V>}
839+
* @returns {Dict<K,V>}
840840
*/
841841
static fromMap(o) {
842-
/** @type PMap<K,V> */
843-
let m = PMap.new();
842+
/** @type Dict<K,V> */
843+
let m = Dict.new();
844844
o.forEach((v, k) => {
845845
m = m.set(k, v);
846846
});
847847
return m;
848848
}
849849
static new() {
850-
return new PMap(undefined, 0);
850+
return new Dict(undefined, 0);
851851
}
852852
/**
853853
* @param {undefined | Node<K,V>} root
@@ -876,7 +876,7 @@ export default class PMap {
876876
/**
877877
* @param {K} key
878878
* @param {V} val
879-
* @returns {PMap<K,V>}
879+
* @returns {Dict<K,V>}
880880
*/
881881
set(key, val) {
882882
const addedLeaf = { val: false };
@@ -885,11 +885,11 @@ export default class PMap {
885885
if (newRoot === this.root) {
886886
return this;
887887
}
888-
return new PMap(newRoot, addedLeaf.val ? this.size + 1 : this.size);
888+
return new Dict(newRoot, addedLeaf.val ? this.size + 1 : this.size);
889889
}
890890
/**
891891
* @param {K} key
892-
* @returns {PMap<K,V>}
892+
* @returns {Dict<K,V>}
893893
*/
894894
delete(key) {
895895
if (this.root === undefined) {
@@ -900,9 +900,9 @@ export default class PMap {
900900
return this;
901901
}
902902
if (newRoot === undefined) {
903-
return PMap.new();
903+
return Dict.new();
904904
}
905-
return new PMap(newRoot, this.size - 1);
905+
return new Dict(newRoot, this.size - 1);
906906
}
907907
/**
908908
* @param {K} key
@@ -945,7 +945,7 @@ export default class PMap {
945945
* @returns {boolean}
946946
*/
947947
equals(o) {
948-
if (!(o instanceof PMap) || this.size !== o.size) {
948+
if (!(o instanceof Dict) || this.size !== o.size) {
949949
return false;
950950
}
951951
let equal = true;

src/gleam_stdlib.mjs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "./gleam/regex.mjs";
1717
import { DecodeError } from "./gleam/dynamic.mjs";
1818
import { Some, None } from "./gleam/option.mjs";
19-
import PMap from "./persistent-hash-map.mjs";
19+
import Dict from "./dict.mjs";
2020

2121
const Nil = undefined;
2222
const NOT_FOUND = {};
@@ -422,7 +422,7 @@ export function regex_scan(regex, string) {
422422
}
423423

424424
export function new_map() {
425-
return PMap.new();
425+
return Dict.new();
426426
}
427427

428428
export function map_size(map) {
@@ -573,7 +573,7 @@ export function classify_dynamic(data) {
573573
return "List";
574574
} else if (data instanceof BitArray) {
575575
return "BitArray";
576-
} else if (data instanceof PMap) {
576+
} else if (data instanceof Dict) {
577577
return "Map";
578578
} else if (Number.isInteger(data)) {
579579
return "Int";
@@ -697,8 +697,8 @@ export function decode_result(data) {
697697
}
698698

699699
export function decode_map(data) {
700-
if (data instanceof PMap) {
701-
return new Ok(PMap.fromMap(data));
700+
if (data instanceof Dict) {
701+
return new Ok(Dict.fromMap(data));
702702
}
703703
if (data == null) {
704704
return decoder_error("Map", data);
@@ -708,7 +708,7 @@ export function decode_map(data) {
708708
}
709709
const proto = Object.getPrototypeOf(data);
710710
if (proto === Object.prototype || proto === null) {
711-
return new Ok(PMap.fromObject(data));
711+
return new Ok(Dict.fromObject(data));
712712
}
713713
return decoder_error("Map", data);
714714
}
@@ -729,7 +729,7 @@ export function decode_field(value, name) {
729729
const not_a_map_error = () => decoder_error("Map", value);
730730

731731
if (
732-
value instanceof PMap ||
732+
value instanceof Dict ||
733733
value instanceof WeakMap ||
734734
value instanceof Map
735735
) {
@@ -796,7 +796,7 @@ export function inspect(v) {
796796
if (v instanceof UtfCodepoint) return inspectUtfCodepoint(v);
797797
if (v instanceof BitArray) return inspectBitArray(v);
798798
if (v instanceof CustomType) return inspectCustomType(v);
799-
if (v instanceof PMap) return inspectMap(v);
799+
if (v instanceof Dict) return inspectDict(v);
800800
if (v instanceof Set) return `//js(Set(${[...v].map(inspect).join(", ")}))`;
801801
if (v instanceof RegExp) return `//js(${v})`;
802802
if (v instanceof Date) return `//js(Date("${v.toISOString()}"))`;
@@ -809,8 +809,8 @@ export function inspect(v) {
809809
return inspectObject(v);
810810
}
811811

812-
function inspectMap(map) {
813-
let body = "map.from_list([";
812+
function inspectDict(map) {
813+
let body = "dict.from_list([";
814814
let first = true;
815815
map.forEach((value, key) => {
816816
if (!first) body = body + ", ";

0 commit comments

Comments
 (0)