diff options
author | Louis Pilfold <louis@lpil.uk> | 2023-11-21 14:44:25 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-11-21 15:11:37 +0000 |
commit | 14e839d3d6b62b1a71df33b0d149bd7580786e4f (patch) | |
tree | 7b8636cb1c84835ed8aab0d6fff04eee60991648 /src | |
parent | fe5d2c9cce6287e90983f28082ae662dea70ee23 (diff) | |
download | gleam_stdlib-14e839d3d6b62b1a71df33b0d149bd7580786e4f.tar.gz gleam_stdlib-14e839d3d6b62b1a71df33b0d149bd7580786e4f.zip |
Rename in JS FFI
Diffstat (limited to 'src')
-rw-r--r-- | src/dict.mjs (renamed from src/persistent-hash-map.mjs) | 30 | ||||
-rw-r--r-- | src/gleam_stdlib.mjs | 20 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/persistent-hash-map.mjs b/src/dict.mjs index 04aadd5..a8309e0 100644 --- a/src/persistent-hash-map.mjs +++ b/src/dict.mjs @@ -814,19 +814,19 @@ function forEach(root, fn) { } } /** - * Extra wrapper to keep track of map size and clean up the API + * Extra wrapper to keep track of Dict size and clean up the API * @template K,V */ -export default class PMap { +export default class Dict { /** * @template V * @param {Record<string,V>} o - * @returns {PMap<string,V>} + * @returns {Dict<string,V>} */ static fromObject(o) { const keys = Object.keys(o); - /** @type PMap<string,V> */ - let m = PMap.new(); + /** @type Dict<string,V> */ + let m = Dict.new(); for (let i = 0; i < keys.length; i++) { const k = keys[i]; m = m.set(k, o[k]); @@ -836,18 +836,18 @@ export default class PMap { /** * @template K,V * @param {Map<K,V>} o - * @returns {PMap<K,V>} + * @returns {Dict<K,V>} */ static fromMap(o) { - /** @type PMap<K,V> */ - let m = PMap.new(); + /** @type Dict<K,V> */ + let m = Dict.new(); o.forEach((v, k) => { m = m.set(k, v); }); return m; } static new() { - return new PMap(undefined, 0); + return new Dict(undefined, 0); } /** * @param {undefined | Node<K,V>} root @@ -876,7 +876,7 @@ export default class PMap { /** * @param {K} key * @param {V} val - * @returns {PMap<K,V>} + * @returns {Dict<K,V>} */ set(key, val) { const addedLeaf = { val: false }; @@ -885,11 +885,11 @@ export default class PMap { if (newRoot === this.root) { return this; } - return new PMap(newRoot, addedLeaf.val ? this.size + 1 : this.size); + return new Dict(newRoot, addedLeaf.val ? this.size + 1 : this.size); } /** * @param {K} key - * @returns {PMap<K,V>} + * @returns {Dict<K,V>} */ delete(key) { if (this.root === undefined) { @@ -900,9 +900,9 @@ export default class PMap { return this; } if (newRoot === undefined) { - return PMap.new(); + return Dict.new(); } - return new PMap(newRoot, this.size - 1); + return new Dict(newRoot, this.size - 1); } /** * @param {K} key @@ -945,7 +945,7 @@ export default class PMap { * @returns {boolean} */ equals(o) { - if (!(o instanceof PMap) || this.size !== o.size) { + if (!(o instanceof Dict) || this.size !== o.size) { return false; } let equal = true; diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index a7405f2..a908b23 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -16,7 +16,7 @@ import { } from "./gleam/regex.mjs"; import { DecodeError } from "./gleam/dynamic.mjs"; import { Some, None } from "./gleam/option.mjs"; -import PMap from "./persistent-hash-map.mjs"; +import Dict from "./dict.mjs"; const Nil = undefined; const NOT_FOUND = {}; @@ -422,7 +422,7 @@ export function regex_scan(regex, string) { } export function new_map() { - return PMap.new(); + return Dict.new(); } export function map_size(map) { @@ -573,7 +573,7 @@ export function classify_dynamic(data) { return "List"; } else if (data instanceof BitArray) { return "BitArray"; - } else if (data instanceof PMap) { + } else if (data instanceof Dict) { return "Map"; } else if (Number.isInteger(data)) { return "Int"; @@ -697,8 +697,8 @@ export function decode_result(data) { } export function decode_map(data) { - if (data instanceof PMap) { - return new Ok(PMap.fromMap(data)); + if (data instanceof Dict) { + return new Ok(Dict.fromMap(data)); } if (data == null) { return decoder_error("Map", data); @@ -708,7 +708,7 @@ export function decode_map(data) { } const proto = Object.getPrototypeOf(data); if (proto === Object.prototype || proto === null) { - return new Ok(PMap.fromObject(data)); + return new Ok(Dict.fromObject(data)); } return decoder_error("Map", data); } @@ -729,7 +729,7 @@ export function decode_field(value, name) { const not_a_map_error = () => decoder_error("Map", value); if ( - value instanceof PMap || + value instanceof Dict || value instanceof WeakMap || value instanceof Map ) { @@ -796,7 +796,7 @@ export function inspect(v) { if (v instanceof UtfCodepoint) return inspectUtfCodepoint(v); if (v instanceof BitArray) return inspectBitArray(v); if (v instanceof CustomType) return inspectCustomType(v); - if (v instanceof PMap) return inspectMap(v); + if (v instanceof Dict) return inspectDict(v); if (v instanceof Set) return `//js(Set(${[...v].map(inspect).join(", ")}))`; if (v instanceof RegExp) return `//js(${v})`; if (v instanceof Date) return `//js(Date("${v.toISOString()}"))`; @@ -809,8 +809,8 @@ export function inspect(v) { return inspectObject(v); } -function inspectMap(map) { - let body = "map.from_list(["; +function inspectDict(map) { + let body = "dict.from_list(["; let first = true; map.forEach((value, key) => { if (!first) body = body + ", "; |