diff options
author | Julian Schurhammer <julian.schurhammer@gmail.com> | 2022-08-13 23:46:10 +1200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-03-13 10:48:58 +0000 |
commit | aae3caf4257adb202d6a6dbabc01dae9dad002c3 (patch) | |
tree | 904e10945c492e8d560cc18cbfe5f676bc2ada4b /src/gleam_stdlib.mjs | |
parent | 507b28c8557af2f74d6504cd75eb687b1fc96a05 (diff) | |
download | gleam_stdlib-aae3caf4257adb202d6a6dbabc01dae9dad002c3.tar.gz gleam_stdlib-aae3caf4257adb202d6a6dbabc01dae9dad002c3.zip |
js map: refactor into class
Diffstat (limited to 'src/gleam_stdlib.mjs')
-rw-r--r-- | src/gleam_stdlib.mjs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index 81304fe..64dc1d0 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -15,7 +15,7 @@ import { } from "./gleam/regex.mjs"; import { DecodeError } from "./gleam/dynamic.mjs"; import { Some, None } from "./gleam/option.mjs"; -import * as pmap from "./persistent-hash-map.mjs"; +import PMap from "./persistent-hash-map.mjs"; const Nil = undefined; const NOT_FOUND = {}; @@ -396,7 +396,7 @@ export function regex_scan(regex, string) { } export function new_map() { - return pmap.create(); + return PMap.new(); } export function map_size(map) { @@ -404,15 +404,15 @@ export function map_size(map) { } export function map_to_list(map) { - return List.fromArray(pmap.entries(map)); + return List.fromArray(map.entries()); } export function map_remove(key, map) { - return pmap.remove(map, key); + return map.delete(key); } export function map_get(map, key) { - const value = pmap.getWithDefault(map, key, NOT_FOUND); + const value = map.get(key, NOT_FOUND); if (value === NOT_FOUND) { return new Error(Nil); } @@ -420,7 +420,7 @@ export function map_get(map, key) { } export function map_insert(key, value, map) { - return pmap.set(map, key, value); + return map.set(key, value); } function unsafe_percent_decode(string) { @@ -551,7 +551,7 @@ export function classify_dynamic(data) { return `Tuple of ${data.length} elements`; } else if (BitString.isBitString(data)) { return "BitString"; - } else if (data instanceof pmap.PMap) { + } else if (data instanceof PMap) { return "Map"; } else if (typeof data === "number") { return "Float"; @@ -621,7 +621,7 @@ export function decode_result(data) { } export function decode_map(data) { - return data instanceof pmap.PMap ? new Ok(data) : decoder_error("Map", data); + return data instanceof PMap ? new Ok(data) : decoder_error("Map", data); } export function decode_option(data, decoder) { @@ -638,7 +638,7 @@ export function decode_option(data, decoder) { export function decode_field(value, name) { let error = () => decoder_error_no_classify("field", "nothing"); - if (value instanceof pmap.PMap) { + if (value instanceof PMap) { let entry = map_get(value, name); return entry.isOk() ? entry : error(); } |