hkt-toolbelt
Version:
Functional and composable type utilities
29 lines (28 loc) • 705 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.collate = void 0;
/**
* Given a number N, take in N curried elements and return a list of N length.
*
* @param {number} n - The number of elements to collate.
*
* @example
* ```ts
* import { List } from "hkt-toolbelt";
*
* const result = List.collate(2)("foo")("bar")
* // ^? ["foo", "bar"]
* ```
*/
exports.collate = ((n) => {
const collector = (values = []) => (value) => {
const newValues = [...values, value];
if (newValues.length === n) {
return newValues;
}
else {
return collector(newValues);
}
};
return collector();
});