2020-01-10 08:36:57 +01:00
|
|
|
import of from UnitJS.Fun;
|
|
|
|
import {compare, of, proj} from UnitJS.Fun;
|
|
|
|
|
2020-01-13 23:08:20 +01:00
|
|
|
function Table(sortCriterion) {
|
2020-01-10 08:36:57 +01:00
|
|
|
var items = {};
|
|
|
|
return {
|
|
|
|
get: get,
|
|
|
|
getAll: getAll,
|
|
|
|
insert: insert,
|
|
|
|
insertAll: insertAll,
|
|
|
|
remove: remove
|
|
|
|
};
|
|
|
|
|
|
|
|
function get(key) {
|
|
|
|
return items[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAll(criterion) {
|
|
|
|
return Object.keys(items)
|
2020-01-13 23:08:20 +01:00
|
|
|
.map(function(key) {return {key: key, value: items[key]};})
|
2020-01-10 08:36:57 +01:00
|
|
|
.filter(criterion || function() {return true;})
|
2020-01-13 23:08:20 +01:00
|
|
|
.sort(compare(sortCriterion));
|
2020-01-10 08:36:57 +01:00
|
|
|
}
|
|
|
|
|
2020-01-13 23:08:20 +01:00
|
|
|
|
2020-01-10 08:36:57 +01:00
|
|
|
function insert(key, value) {
|
2020-01-13 23:08:20 +01:00
|
|
|
items[key] = value;
|
2020-01-10 08:36:57 +01:00
|
|
|
}
|
|
|
|
|
2020-01-11 19:46:41 +01:00
|
|
|
function insertAll(newItems) {
|
|
|
|
for(var key in newItems) {
|
|
|
|
insert(key, newItems[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 08:36:57 +01:00
|
|
|
function remove(key) {
|
|
|
|
delete items[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
make: Table
|
|
|
|
}
|