UNPKG

macoolka-collection

Version:

`macoolka-collection` Define Data Collection Interface.

58 lines 2.93 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initWriter = void 0; var O = require("fp-ts/Option"); var pipeable_1 = require("fp-ts/pipeable"); function initWriter(option) { var size = option.size, _insertAt = option._insertAt, _deleteAt = option._deleteAt, getAt = option.getAt, _setAt = option._setAt, existAt = option.existAt, findIndex = option.findIndex, _getAt = option._getAt; var insertAt = function (i, a) { return function (as) { return (0, pipeable_1.pipe)(as, O.fromPredicate(function (as) { return i <= size(as) && i >= 0; }), O.map((0, pipeable_1.pipe)(_insertAt(i, a)))); }; }; var deleteAt = function (i) { return function (as) { return (0, pipeable_1.pipe)(as, O.fromPredicate(existAt(i)), O.map((0, pipeable_1.pipe)(_deleteAt(i)))); }; }; var setAt = function (i, a) { return function (as) { return (0, pipeable_1.pipe)(as, O.fromPredicate(existAt(i)), O.map((0, pipeable_1.pipe)(_setAt(i, a)))); }; }; var cons = function (head) { return function (as) { return (0, pipeable_1.pipe)(as, insertAt(0, head), O.getOrElse(function () { return as; })); }; }; var snoc = function (end) { return function (as) { return (0, pipeable_1.pipe)(as, insertAt(size(as), end), O.getOrElse(function () { return as; })); }; }; var updateAt = function (i, updater) { return function (as) { return (0, pipeable_1.pipe)(as, getAt(i), O.chain(function (value) { return (0, pipeable_1.pipe)(as, setAt(i, updater(value))); })); }; }; var deleteWith = function (predicate) { return function (as) { return (0, pipeable_1.pipe)(as, findIndex(predicate), function (indexs) { var ns = indexs.reverse(); var store = as; ns.map(function (i) { store = _deleteAt(i)(store); }); return store; }); }; }; var upateWith = function (predicate, updater) { return function (as) { return (0, pipeable_1.pipe)(as, findIndex(predicate), function (indexs) { var ns = indexs.reverse(); var store = as; ns.map(function (i) { store = _setAt(i, updater(_getAt(i)(store)))(store); }); return store; }); }; }; return __assign({ cons: cons, snoc: snoc, push: snoc, updateAt: updateAt, insertAt: insertAt, setAt: setAt, deleteWith: deleteWith, updateWith: upateWith, deleteAt: deleteAt, add: snoc }, option); } exports.initWriter = initWriter; //# sourceMappingURL=IndexWriterCollection.js.map