UNPKG

pragmatic-fp-ts

Version:

Opinionated functional programming library with easy use in mind

20 lines (19 loc) 606 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dropRepeats = void 0; const main_1 = require("./main"); // Remove successive repeats in a list, leaving only one copy function dropRepeats(coll) { const theColl = (0, main_1.getValueOr)([], coll); const result = []; let lastVal; for (let i = 0; i < theColl.length; ++i) { const nextVal = theColl[i]; if (i === 0 || !(0, main_1.equals)(nextVal, lastVal)) { result.push(nextVal); } lastVal = nextVal; } return result; } exports.dropRepeats = dropRepeats;