UNPKG

@unsplash/sum-types-fast-check

Version:
14 lines (13 loc) 543 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getArb = exports.nullaryArb = void 0; const fast_check_1 = require("fast-check"); exports.nullaryArb = fast_check_1.default.constant(null); const getArb = (sum) => (arbs) => { const tags = Object.keys(arbs); const tagArb = fast_check_1.default.constantFrom(...tags); return (tagArb .chain(tag => arbs[tag].map(val => [tag, val])) .map(([tag, val]) => (val === null ? sum.mk[tag] : sum.mk[tag](val)))); }; exports.getArb = getArb;