pragmatic-fp-ts
Version:
Opinionated functional programming library with easy use in mind
20 lines (19 loc) • 626 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.intersperse = void 0;
const main_1 = require("./main");
function intersperse(elem, coll) {
if (arguments.length === 1)
return (_coll) => intersperse(elem, _coll);
const theElem = (0, main_1.getValue)(elem);
const theColl = (0, main_1.getValueOr)([], coll);
const result = [];
for (let i = 0; i < theColl.length - 1; ++i) {
result.push(theColl[i], theElem);
}
if (theColl.length > 0) {
result.push(theColl[theColl.length - 1]);
}
return result;
}
exports.intersperse = intersperse;