forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJs_dict.js
85 lines (74 loc) · 1.39 KB
/
Js_dict.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as Primitive_option from "./Primitive_option.js";
function get(dict, k) {
if ((k in dict)) {
return Primitive_option.some(dict[k]);
}
}
let unsafeDeleteKey = (function (dict,key){
delete dict[key];
});
function entries(dict) {
let keys = Object.keys(dict);
let l = keys.length;
let values = new Array(l);
for (let i = 0; i < l; ++i) {
let key = keys[i];
values[i] = [
key,
dict[key]
];
}
return values;
}
function values(dict) {
let keys = Object.keys(dict);
let l = keys.length;
let values$1 = new Array(l);
for (let i = 0; i < l; ++i) {
values$1[i] = dict[keys[i]];
}
return values$1;
}
function fromList(entries) {
let dict = {};
let _x = entries;
while (true) {
let x = _x;
if (x === 0) {
return dict;
}
let match = x.hd;
dict[match[0]] = match[1];
_x = x.tl;
continue;
};
}
function fromArray(entries) {
let dict = {};
let l = entries.length;
for (let i = 0; i < l; ++i) {
let match = entries[i];
dict[match[0]] = match[1];
}
return dict;
}
function map(f, source) {
let target = {};
let keys = Object.keys(source);
let l = keys.length;
for (let i = 0; i < l; ++i) {
let key = keys[i];
target[key] = f(source[key]);
}
return target;
}
export {
get,
unsafeDeleteKey,
entries,
values,
fromList,
fromArray,
map,
}
/* No side effect */