2024-10-17 21:31:23 +03:00

15 lines
615 B
JavaScript

import { tuple } from './tuple.js';
import { uniqueArray } from './uniqueArray.js';
import { keyValuePairsToObjectMapper, keyValuePairsToObjectUnmapper } from './_internals/mappers/KeyValuePairsToObject.js';
function dictionaryKeyExtractor(entry) {
return entry[0];
}
export function dictionary(keyArb, valueArb, constraints = {}) {
return uniqueArray(tuple(keyArb, valueArb), {
minLength: constraints.minKeys,
maxLength: constraints.maxKeys,
size: constraints.size,
selector: dictionaryKeyExtractor,
}).map(keyValuePairsToObjectMapper, keyValuePairsToObjectUnmapper);
}