UNPKG

macoolka-collection

Version:

`macoolka-collection` Define Data Collection Interface.

128 lines 9.67 kB
"use strict"; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); var O = require("fp-ts/Option"); var pipeable_1 = require("fp-ts/pipeable"); var throwError = function () { throw new Error('error'); }; function test(_a) { var from = _a.from, size = _a.size, empty = _a.empty, getiterator = _a.getiterator, head = _a.head, tail = _a.tail, takeLeft = _a.takeLeft, takeLeftWhile = _a.takeLeftWhile, takeLeftUntil = _a.takeLeftUntil, takeRight = _a.takeRight, skipLeft = _a.skipLeft, skipLeftWhile = _a.skipLeftWhile, skipLeftUntil = _a.skipLeftUntil, skipRight = _a.skipRight, splitAt = _a.splitAt, spanLeft = _a.spanLeft, clear = _a.clear, slice = _a.slice; var as = from([1, 2, 3]); describe('Collection Reader', function () { it('slice', function () { (0, pipeable_1.pipe)([1, 2, 3, 4, 5], from, slice(2), expect(from([3, 4, 5])).toEqual); (0, pipeable_1.pipe)([1, 2, 3, 4, 5], from, slice(2, 4), expect(from([3, 4])).toEqual); (0, pipeable_1.pipe)([1, 2, 3, 4, 5], from, slice(1, 5), expect(from([2, 3, 4, 5])).toEqual); }); it('tail', function () { (0, pipeable_1.pipe)(tail(as), O.fold(throwError, function (value) { return (0, pipeable_1.pipe)(value, getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 3]).toEqual); })); (0, pipeable_1.pipe)(tail(from([])), expect(O.none).toEqual); }); it('takeLeft', function () { (0, pipeable_1.pipe)(takeLeft(2)(as), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1, 2]).toEqual); (0, pipeable_1.pipe)(takeLeft(0)(as), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(takeLeft(2)(from([])), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); }); it('takeRight', function () { (0, pipeable_1.pipe)(takeRight(2)(as), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 3]).toEqual); (0, pipeable_1.pipe)(takeRight(0)(as), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(takeRight(2)(from([])), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); }); it('spanLeft', function () { (0, pipeable_1.pipe)(from([1, 3, 2, 4, 5]), spanLeft(function (n) { return n % 2 === 1; }), expect({ init: from([1, 3]), rest: from([2, 4, 5]) }).toEqual); var isNumber = function (u) { return typeof u === 'number'; }; (0, pipeable_1.pipe)(from([1, 'a', 3]), spanLeft(isNumber), expect({ init: from([1]), rest: from(['a', 3]) }).toEqual); }); it('takeLeftWhile', function () { var f = function (n) { return n % 2 === 0; }; (0, pipeable_1.pipe)(from([2, 4, 3, 6]), takeLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 4]).toEqual); (0, pipeable_1.pipe)(empty(), takeLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(from([1, 2, 4]), takeLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(from([2, 4]), takeLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 4]).toEqual); }); it('takeLeftUntil', function () { var f = function (n) { return n % 2 === 1; }; (0, pipeable_1.pipe)(from([2, 4, 3, 6]), takeLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 4]).toEqual); (0, pipeable_1.pipe)(empty(), takeLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(from([1, 2, 4]), takeLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(from([2, 4]), takeLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 4]).toEqual); }); it('skipLeft', function () { (0, pipeable_1.pipe)(as, skipLeft(2), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([3]).toEqual); (0, pipeable_1.pipe)(as, skipLeft(5), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(as, skipLeft(0), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1, 2, 3]).toEqual); }); it('skipRight', function () { (0, pipeable_1.pipe)(as, skipRight(2), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1]).toEqual); (0, pipeable_1.pipe)(as, skipRight(5), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(as, skipRight(0), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1, 2, 3]).toEqual); }); it('skipLeftWhile', function () { var f = function (n) { return n % 2 === 0; }; var g = function (n) { return n % 2 === 1; }; (0, pipeable_1.pipe)(from([1, 3, 2, 4, 5]), skipLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1, 3, 2, 4, 5]).toEqual); (0, pipeable_1.pipe)(from([1, 3, 2, 4, 5]), skipLeftWhile(g), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 4, 5]).toEqual); (0, pipeable_1.pipe)(from([2, 4, 1]), skipLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1]).toEqual); (0, pipeable_1.pipe)(from([2, 4]), skipLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(from([]), skipLeftWhile(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); }); it('skipLeftWhile', function () { var f = function (n) { return n % 2 === 1; }; var g = function (n) { return n % 2 === 0; }; (0, pipeable_1.pipe)(from([1, 3, 2, 4, 5]), skipLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1, 3, 2, 4, 5]).toEqual); (0, pipeable_1.pipe)(from([1, 3, 2, 4, 5]), skipLeftUntil(g), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([2, 4, 5]).toEqual); (0, pipeable_1.pipe)(from([2, 4, 1]), skipLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1]).toEqual); (0, pipeable_1.pipe)(from([2, 4]), skipLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); (0, pipeable_1.pipe)(from([]), skipLeftUntil(f), getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([]).toEqual); }); it('head', function () { (0, pipeable_1.pipe)(as, head, O.fold(throwError, function (value) { return (0, pipeable_1.pipe)(value, getiterator, function (a) { return __spreadArray([], __read(a), false); }, expect([1, 2]).toEqual); })); (0, pipeable_1.pipe)(from([]), head, expect(O.none).toEqual); }); it('splitAt', function () { (0, pipeable_1.pipe)(from([1, 2, 3, 4, 5]), splitAt(2), expect([from([1, 2]), from([3, 4, 5])]).toEqual); (0, pipeable_1.pipe)(from([]), splitAt(2), expect([from([]), from([])]).toEqual); (0, pipeable_1.pipe)(from([1]), splitAt(2), expect([from([1]), from([])]).toEqual); (0, pipeable_1.pipe)(from([1, 2]), splitAt(2), expect([from([1, 2]), from([])]).toEqual); (0, pipeable_1.pipe)(from([1, 2]), splitAt(-1), expect([from([1]), from([2])]).toEqual); (0, pipeable_1.pipe)(from([1, 2]), splitAt(0), expect([from([]), from([1, 2])]).toEqual); (0, pipeable_1.pipe)(from([1, 2]), splitAt(3), expect([from([1, 2]), from([])]).toEqual); }); it('clear', function () { (0, pipeable_1.pipe)(as, clear, size, expect(0).toEqual); }); }); } exports.default = test; //# sourceMappingURL=Subset.js.map