84 lines
1.5 KiB
JavaScript
84 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
var Caml_option = require("./caml_option.js");
|
|
|
|
function get(dict, k) {
|
|
if ((k in dict)) {
|
|
return Caml_option.some(dict[k]);
|
|
}
|
|
|
|
}
|
|
|
|
var unsafeDeleteKey = (function (dict,key){
|
|
delete dict[key];
|
|
});
|
|
|
|
function entries(dict) {
|
|
var keys = Object.keys(dict);
|
|
var l = keys.length;
|
|
var values = new Array(l);
|
|
for(var i = 0; i < l; ++i){
|
|
var key = keys[i];
|
|
values[i] = [
|
|
key,
|
|
dict[key]
|
|
];
|
|
}
|
|
return values;
|
|
}
|
|
|
|
function values(dict) {
|
|
var keys = Object.keys(dict);
|
|
var l = keys.length;
|
|
var values$1 = new Array(l);
|
|
for(var i = 0; i < l; ++i){
|
|
values$1[i] = dict[keys[i]];
|
|
}
|
|
return values$1;
|
|
}
|
|
|
|
function fromList(entries) {
|
|
var dict = {};
|
|
var _param = entries;
|
|
while(true) {
|
|
var param = _param;
|
|
if (!param) {
|
|
return dict;
|
|
}
|
|
var match = param.hd;
|
|
dict[match[0]] = match[1];
|
|
_param = param.tl;
|
|
continue ;
|
|
};
|
|
}
|
|
|
|
function fromArray(entries) {
|
|
var dict = {};
|
|
var l = entries.length;
|
|
for(var i = 0; i < l; ++i){
|
|
var match = entries[i];
|
|
dict[match[0]] = match[1];
|
|
}
|
|
return dict;
|
|
}
|
|
|
|
function map(f, source) {
|
|
var target = {};
|
|
var keys = Object.keys(source);
|
|
var l = keys.length;
|
|
for(var i = 0; i < l; ++i){
|
|
var key = keys[i];
|
|
target[key] = f(source[key]);
|
|
}
|
|
return target;
|
|
}
|
|
|
|
exports.get = get;
|
|
exports.unsafeDeleteKey = unsafeDeleteKey;
|
|
exports.entries = entries;
|
|
exports.values = values;
|
|
exports.fromList = fromList;
|
|
exports.fromArray = fromArray;
|
|
exports.map = map;
|
|
/* No side effect */
|