declarative-js
Version:
_declarative-js_ is modern JavaScript library, that helps to: - tackle array transformation with built in JavaScript array api (e.g. `array.filter(toBe.unique())`), - provide a type-level solution for representing optional values instead of null referen
20 lines (19 loc) • 906 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var reducer_utils_1 = require("./reducer.utils");
exports.toMapKeyMap = function (getKey) { return function (agr, value, index, array) {
var key = reducer_utils_1.valid(getKey(value));
if (agr.containsKey(key)) {
throw new Error("Key: \"" + key + "\" has duplicates");
}
agr.put(key, value);
return reducer_utils_1.isLastElement(array, index) ? reducer_utils_1.finalizeMap(agr) : agr;
}; };
exports.toMapAndValue = function (getKey, getValue) { return function (agr, value, index, array) {
var key = reducer_utils_1.valid(getKey(value));
if (agr.containsKey(key)) {
throw new Error("Key: \"" + key + "\" has duplicates");
}
agr.put(key, getValue(value));
return reducer_utils_1.isLastElement(array, index) ? reducer_utils_1.finalizeMap(agr) : agr;
}; };