macoolka-collection
Version:
`macoolka-collection` Define Data Collection Interface.
427 lines • 26.7 kB
JavaScript
;
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var O = require("fp-ts/Option");
var E = require("fp-ts/Either");
var Functor_1 = require("fp-ts/Functor");
var pipeable_1 = require("fp-ts/pipeable");
var Monoid_1 = require("fp-ts/Monoid");
var Ord_1 = require("fp-ts/Ord");
var Eq_1 = require("fp-ts/Eq");
var basic_1 = require("./fixtures/basic");
var Show_1 = require("fp-ts/Show");
var I = require("fp-ts/Identity");
function test(_a) {
var _getAt = _a._getAt, spanLeft = _a.spanLeft, from = _a.from, empty = _a.empty, of = _a.of, reverse = _a.reverse, size = _a.size, collection = _a.collection, alt = _a.alt, zero = _a.zero, mapWithIndex = _a.mapWithIndex, map = _a.map, flatten = _a.flatten, toArray = _a.toArray, sequenceS = _a.sequenceS, sequenceT = _a.sequenceT, ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, reduce = _a.reduce, reduceRight = _a.reduceRight, foldMap = _a.foldMap, foldM = _a.foldM, reduceWithIndex = _a.reduceWithIndex, reduceRightWithIndex = _a.reduceRightWithIndex, foldMapWithIndex = _a.foldMapWithIndex, unfold = _a.unfold, compact = _a.compact, separate = _a.separate, filter = _a.filter, filterMap = _a.filterMap, filterMapWithIndex = _a.filterMapWithIndex, filterWithIndex = _a.filterWithIndex, partition = _a.partition, partitionMap = _a.partitionMap, partitionMapWithIndex = _a.partitionMapWithIndex, partitionWithIndex = _a.partitionWithIndex, getEq = _a.getEq, getOrd = _a.getOrd, getShow = _a.getShow, getMonoid = _a.getMonoid, rights = _a.rights, lefts = _a.lefts, rotate = _a.rotate, zip = _a.zip, zipWith = _a.zipWith, unzip = _a.unzip, sort = _a.sort, sortBy = _a.sortBy, scanLeft = _a.scanLeft, scanRight = _a.scanRight, uniq = _a.uniq, intersection = _a.intersection, union = _a.union, difference = _a.difference, foldLeft = _a.foldLeft, foldRight = _a.foldRight, traverse = _a.traverse, traverseWithIndex = _a.traverseWithIndex, sequence = _a.sequence, wilt = _a.wilt, wither = _a.wither, extend = _a.extend, duplicate = _a.duplicate, chop = _a.chop, groupBy = _a.groupBy, comprehension = _a.comprehension, toRecord = _a.toRecord, fromRecord = _a.fromRecord;
var as = from([1, 2, 3]);
var toEqual = function (a) { return function (b) { return expect(a).toEqual(b); }; };
describe('Collection Reader', function () {
it('alt', function () {
expect(alt(function () { return from([3, 4]); })(from([1, 2]))).toEqual(from([1, 2, 3, 4]));
expect(collection.alt(from([1, 2]), function () { return from([3, 4]); })).toEqual(from([1, 2, 3, 4]));
});
it('zero', function () {
expect(zero()).toEqual(empty());
});
it('map', function () {
(0, pipeable_1.pipe)(as, map(function (n) { return n * 2; }), expect(from([2, 4, 6])).toEqual);
(0, pipeable_1.pipe)(from(Object.entries({ name: '1', value: '2' })), map(function (_a) {
var _b = __read(_a, 1), n = _b[0];
return n;
}), expect(from(['name', 'value'])).toEqual);
(0, pipeable_1.pipe)(empty(), map(function (n) { return n * 2; }), expect(empty()).toEqual);
(0, pipeable_1.pipe)(collection.map(as, function (n) { return n * 2; }), expect(from([2, 4, 6])).toEqual);
(0, pipeable_1.pipe)(collection.map(empty(), function (n) { return n * 2; }), expect(empty()).toEqual);
});
it('mapWithIndex', function () {
(0, pipeable_1.pipe)(as, mapWithIndex(function (i, n) { return n * 2 + i; }), expect(from([2, 5, 8])).toEqual);
(0, pipeable_1.pipe)(collection.mapWithIndex(as, function (i, n) { return n * 2 + i; }), expect(from([2, 5, 8])).toEqual);
});
it('getFunctorComposition', function () {
var L = (0, Functor_1.getFunctorComposition)(collection, O.option);
var optionList = from([O.some(1), O.some(2), O.some(3), O.none]);
var result = L.map(optionList, function (a) { return a * 2; });
expect(result).toEqual(from([O.some(2), O.some(4), O.some(6), O.none]));
var L1 = (0, Functor_1.getFunctorComposition)(O.option, collection);
var optionList1 = O.some(as);
var result1 = L1.map(optionList1, function (a) { return a * 2; });
if (O.isSome(result1)) {
expect(result1.value).toEqual(from([2, 4, 6]));
}
else {
throw new Error('can not none');
}
});
it('ap', function () {
(0, pipeable_1.pipe)(from([function (x) { return x * 2; }, function (x) { return x * 3; }]), ap(from([1, 2, 3])), expect(from([2, 4, 6, 3, 6, 9])).toEqual);
var as = collection.ap(from([function (x) { return x * 2; }, function (x) { return x * 3; }]), from([1, 2, 3]));
expect(as).toEqual(from([2, 4, 6, 3, 6, 9]));
});
it('apFirst', function () {
(0, pipeable_1.pipe)(from([1]), apFirst(from([2])), expect(from([1])).toEqual);
});
it('apSecond', function () {
(0, pipeable_1.pipe)(from([1]), apSecond(from([2])), expect(from([2])).toEqual);
});
it('sequenceS', function () {
(0, pipeable_1.pipe)({
a: from(['1']),
b: from([2])
}, sequenceS, expect(from([{ a: '1', b: 2 }])).toEqual);
});
it('sequenceT', function () {
(0, pipeable_1.pipe)(sequenceT(from([1]), from([2])), toArray, expect([1, 2]).toEqual);
});
it('chain', function () {
(0, pipeable_1.pipe)(from([1, 2, 3]), chain(function (n) { return from([n, n + 1]); }), expect(from([1, 2, 2, 3, 3, 4])).toEqual);
(0, pipeable_1.pipe)(collection.chain(from([1, 2, 3]), function (n) { return from([n, n + 1]); }), expect(from([1, 2, 2, 3, 3, 4])).toEqual);
});
it('chainFirst', function () {
(0, pipeable_1.pipe)(from([1]), chainFirst(function (n) { return from([n, n + 1]); }), expect(from([1])).toEqual);
});
it('flatten', function () {
(0, pipeable_1.pipe)(from([from([1]), from([2]), from([3])]), flatten, toArray, expect([1, 2, 3]).toEqual);
});
it('reduce', function () {
(0, pipeable_1.pipe)(as, reduce('', function (a, b) { return a + b.toString(); }), expect('123').toEqual);
(0, pipeable_1.pipe)(collection.reduce(as, '', function (a, b) { return a + b.toString(); }), expect('123').toEqual);
});
it('reduceWithIndex', function () {
(0, pipeable_1.pipe)(as, reduceWithIndex('', function (i, a, b) { return i + a + b.toString(); }), expect('210123').toEqual);
(0, pipeable_1.pipe)(collection.reduceWithIndex(as, '', function (i, a, b) { return i + a + b.toString(); }), expect('210123').toEqual);
});
it('foldMap', function () {
(0, pipeable_1.pipe)(as, foldMap(Monoid_1.monoidString)(function (a) { return a.toString(); }), expect('123').toEqual);
(0, pipeable_1.pipe)(empty(), foldMap(Monoid_1.monoidString)(function (a) { return a.toString(); }), expect('').toEqual);
(0, pipeable_1.pipe)(collection.foldMap(Monoid_1.monoidString)(as, function (a) { return a.toString(); }), expect('123').toEqual);
(0, pipeable_1.pipe)(collection.foldMap(Monoid_1.monoidString)(empty(), function (a) { return a.toString(); }), expect('').toEqual);
});
it('foldMapWithIndex', function () {
(0, pipeable_1.pipe)(as, foldMapWithIndex(Monoid_1.monoidString)(function (i, a) { return i + a.toString(); }), expect('011223').toEqual);
(0, pipeable_1.pipe)(empty(), foldMapWithIndex(Monoid_1.monoidString)(function (a) { return a.toString(); }), expect('').toEqual);
(0, pipeable_1.pipe)(collection.foldMapWithIndex(Monoid_1.monoidString)(as, function (i, a) { return i + a.toString(); }), expect('011223').toEqual);
(0, pipeable_1.pipe)(collection.foldMapWithIndex(Monoid_1.monoidString)(empty(), function (a) { return a.toString(); }), expect('').toEqual);
});
it('reduceRight', function () {
(0, pipeable_1.pipe)(as, reduceRight('', function (b, a) { return a + b.toString(); }), expect('123').toEqual);
(0, pipeable_1.pipe)(collection.reduceRight(as, '', function (b, a) { return a + b.toString(); }), expect('123').toEqual);
});
it('reduceRightWithIndex', function () {
(0, pipeable_1.pipe)(as, reduceRightWithIndex('', function (i, b, a) { return i + a + b.toString(); }), expect('210123').toEqual);
(0, pipeable_1.pipe)(collection.reduceRightWithIndex(as, '', function (i, b, a) { return i.toString() + a + b.toString(); }), expect('210123').toEqual);
});
it('foldM', function () {
expect(foldM(O.option)(as, 0, function (a, b) { return O.some(a + b); })).toEqual(O.some(6));
});
it('unfold', function () {
var as = unfold(5, function (n) { return (n > 0 ? O.some([n, n - 1]) : O.none); });
expect(as).toEqual(from([5, 4, 3, 2, 1]));
});
it('compact', function () {
expect(compact(empty())).toEqual(empty());
var a = compact(from([O.some(1), O.some(2), O.none]));
expect(a).toEqual(from([1, 2]));
});
it('separate', function () {
expect(separate(empty())).toEqual({ left: empty(), right: empty() });
expect(separate(from([E.left(123), E.right('123')]))).toEqual({ left: from([123]), right: from(['123']) });
});
it('filter', function () {
var g = function (n) { return n % 2 === 1; };
expect(filter(g)(as)).toEqual(from([1, 3]));
(0, pipeable_1.pipe)([O.some(3), O.some(2), O.some(1)], from, filter(O.isSome), toArray, expect([O.some(3), O.some(2), O.some(1)]).toEqual);
(0, pipeable_1.pipe)([O.some(3), O.some(2), O.some(1), O.none], from, filter(O.isSome), toArray, expect([O.some(3), O.some(2), O.some(1)]).toEqual);
});
it('filterWithIndex', function () {
var f = function (n) { return n % 2 === 1; };
(0, pipeable_1.pipe)(as, filterWithIndex(f), expect(from([2])).toEqual);
});
it('filterMap', function () {
var f = function (n) { return (n % 2 === 0 ? O.none : O.some(n)); };
expect(filterMap(f)(as)).toEqual(from([1, 3]));
});
it('filterMapWithIndex', function () {
var f = function (n) { return (n % 2 ? O.none : O.some(n)); };
(0, pipeable_1.pipe)(as, filterMapWithIndex(f), expect(from([0, 2])).toEqual);
});
it('partition', function () {
var f = function (n) { return (n % 2 === 1); };
expect(partition(function (_) { return true; })(empty())).toEqual({ left: empty(), right: empty() });
expect(partition(f)(as)).toEqual({ left: from([2]), right: from([1, 3]) });
});
it('partitionWithIndex', function () {
var f = function (n) { return (n % 2 === 1); };
(0, pipeable_1.pipe)(as, partitionWithIndex(f), expect({ left: from([1, 3]), right: from([2,]) }).toEqual);
});
it('partitionMap', function () {
var f = function (n) { return (n % 2 === 0 ? E.left(n) : E.right(n)); };
expect(partitionMap(function (_) { return E.left(1); })(empty())).toEqual({ left: empty(), right: empty() });
expect(partitionMap(f)(as)).toEqual({ left: from([2]), right: from([1, 3]) });
});
it('partitionMapWithIndex', function () {
var f = function (n) { return (n % 2 === 0 ? E.left(n) : E.right(n)); };
(0, pipeable_1.pipe)(as, partitionMapWithIndex(f), expect({ left: from([0, 2]), right: from([1]) }).toEqual);
});
it('getMonoid', function () {
var M = getMonoid();
expect(M.concat(from([1, 2]), from([3, 4]))).toEqual(from([1, 2, 3, 4]));
expect(M.concat(from([1, 2]), M.empty)).toEqual(from([1, 2]));
expect(M.concat(M.empty, from([1, 2]))).toEqual(from([1, 2]));
});
it('getEq', function () {
var O = getEq(Ord_1.ordString);
expect(O.equals(from([]), from([]))).toEqual(true);
expect(O.equals(from(['a']), from(['a']))).toEqual(true);
expect(O.equals(from(['a', 'b']), from(['a', 'b']))).toEqual(true);
expect(O.equals(from(['a']), from([]))).toEqual(false);
});
it('getOrd', function () {
var O = getOrd(Ord_1.ordString);
expect(O.compare(from([]), from([]))).toEqual(0);
expect(O.compare(from(['a']), from(['a']))).toEqual(0);
expect(O.compare(from(['b']), from(['a']))).toEqual(1);
expect(O.compare(from(['a']), from(['b']))).toEqual(-1);
expect(O.compare(from(['a']), from([]))).toEqual(1);
expect(O.compare(from([]), from(['a']))).toEqual(-1);
expect(O.compare(from(['a', 'a']), from(['a']))).toEqual(1);
expect(O.compare(from(['a', 'a']), from(['b']))).toEqual(-1);
expect(O.compare(from(['a', 'a']), from(['a', 'a']))).toEqual(0);
expect(O.compare(from(['a', 'b']), from(['a', 'b']))).toEqual(0);
expect(O.compare(from(['a', 'a']), from(['a', 'b']))).toEqual(-1);
expect(O.compare(from(['a', 'b']), from(['a', 'a']))).toEqual(1);
expect(O.compare(from(['a', 'b']), from(['b', 'a']))).toEqual(-1);
expect(O.compare(from(['b', 'a']), from(['a', 'a']))).toEqual(1);
expect(O.compare(from(['b', 'a']), from(['a', 'b']))).toEqual(1);
expect(O.compare(from(['b', 'b']), from(['b', 'a']))).toEqual(1);
expect(O.compare(from(['b', 'a']), from(['b', 'b']))).toEqual(-1);
});
it('getShow', function () {
var show = (0, Show_1.getStructShow)({
id: Show_1.showString,
name: Show_1.showString,
});
expect(getShow(show).show(from(basic_1.data))).toMatchSnapshot();
var S = getShow(Show_1.showString);
expect(S.show(from([]))).toEqual("[]");
expect(S.show(from(['a']))).toEqual("[\"a\"]");
expect(S.show(from(['a', 'b']))).toEqual("[\"a\", \"b\"]");
});
it('rights', function () {
(0, pipeable_1.pipe)(rights(from([E.right(1), E.left('foo'), E.right(2)])), toArray, expect([1, 2]).toEqual);
(0, pipeable_1.pipe)(rights(empty()), toArray, expect([]).toEqual);
});
it('lefts', function () {
(0, pipeable_1.pipe)(lefts(from([E.right(1), E.left('foo'), E.right(2)])), toArray, expect(['foo']).toEqual);
(0, pipeable_1.pipe)(lefts(empty()), toArray, expect([]).toEqual);
});
it('rotate', function () {
(0, pipeable_1.pipe)(empty(), rotate(1), toArray, expect([]).toEqual);
(0, pipeable_1.pipe)(from([1, 2]), rotate(1), toArray, expect([2, 1]).toEqual);
});
it('zipWith', function () {
(0, pipeable_1.pipe)(zipWith(from([1, 2, 3]), from(['a', 'b', 'c', 'd']), function (n, s) { return s + n; }), toArray, expect(['a1', 'b2', 'c3']).toEqual);
});
it('zip', function () {
(0, pipeable_1.pipe)(zip(from([1, 2, 3]), from(['a', 'b', 'c', 'd'])), toArray, expect([[1, 'a'], [2, 'b'], [3, 'c']]).toEqual);
});
it('unzip', function () {
(0, pipeable_1.pipe)(unzip(from([
[1, 'a'],
[2, 'b'],
[3, 'c']
])), expect([from([1, 2, 3]), from(['a', 'b', 'c'])]).toEqual);
});
it('scanLeft', function () {
var f = function (b, a) { return b - a; };
(0, pipeable_1.pipe)(as, scanLeft(10, f), toArray, expect([10, 9, 7, 4]).toEqual);
(0, pipeable_1.pipe)(from([0]), scanLeft(10, f), toArray, expect([10, 10]).toEqual);
(0, pipeable_1.pipe)(empty(), scanLeft(10, f), toArray, expect([10]).toEqual);
});
it('scanRight', function () {
var f = function (b, a) { return b - a; };
(0, pipeable_1.pipe)(as, scanRight(10, f), toArray, expect([-8, 9, -7, 10]).toEqual);
(0, pipeable_1.pipe)(from([0]), scanRight(10, f), toArray, expect([-10, 10]).toEqual);
(0, pipeable_1.pipe)(empty(), scanRight(10, f), toArray, expect([10]).toEqual);
});
it('sort', function () {
(0, pipeable_1.pipe)(from([3, 2, 1]), sort(Ord_1.ordNumber), toArray, expect([1, 2, 3]).toEqual);
});
it('sortBy', function () {
var byName = Ord_1.ord.contramap(Ord_1.ordString, function (p) { return p.name; });
var byAge = Ord_1.ord.contramap(Ord_1.ordNumber, function (p) { return p.age; });
var sortByNameByAge = sortBy([byName, byAge]);
var persons = from([{ name: 'a', age: 1 }, { name: 'b', age: 3 }, { name: 'c', age: 2 }, { name: 'b', age: 2 }]);
expect(sortByNameByAge(persons)).toEqual(from([
{ name: 'a', age: 1 },
{ name: 'b', age: 2 },
{ name: 'b', age: 3 },
{ name: 'c', age: 2 }
]));
var sortByAgeByName = sortBy([byAge, byName]);
expect(sortByAgeByName(persons)).toEqual(from([
{ name: 'a', age: 1 },
{ name: 'b', age: 2 },
{ name: 'c', age: 2 },
{ name: 'b', age: 3 }
]));
});
it('uniq', function () {
var eqA = Eq_1.eq.contramap(Ord_1.ordNumber, function (f) { return f.b; });
var arrA = { a: 'a', b: 1 };
var arrB = { a: 'b', b: 1 };
var arrC = { a: 'c', b: 2 };
var arrD = { a: 'd', b: 2 };
var arrUniq = [arrA, arrC];
(0, pipeable_1.pipe)(arrUniq, from, uniq(eqA), toArray, expect(arrUniq).toEqual);
(0, pipeable_1.pipe)([arrA, arrB, arrC, arrD], from, uniq(eqA), toArray, expect([arrA, arrC]).toEqual);
(0, pipeable_1.pipe)([arrA, arrA, arrC, arrD, arrA], from, uniq(eqA), toArray, expect([arrA, arrC]).toEqual);
(0, pipeable_1.pipe)([arrA, arrC], from, uniq(eqA), toArray, expect([arrA, arrC]).toEqual);
(0, pipeable_1.pipe)([arrC, arrA], from, uniq(eqA), toArray, expect([arrC, arrA]).toEqual);
});
it('union', function () {
(0, pipeable_1.pipe)(union(Ord_1.ordNumber)(from([1, 2]), from([3, 4])), toArray, expect([1, 2, 3, 4]).toEqual);
(0, pipeable_1.pipe)(union(Ord_1.ordNumber)(from([1, 2]), from([2, 3])), toArray, expect([1, 2, 3]).toEqual);
(0, pipeable_1.pipe)(union(Ord_1.ordNumber)(from([1, 2]), from([1, 2])), toArray, expect([1, 2]).toEqual);
});
it('intersection', function () {
(0, pipeable_1.pipe)(intersection(Ord_1.ordNumber)(from([1, 2]), from([3, 4])), toArray, expect([]).toEqual);
(0, pipeable_1.pipe)(intersection(Ord_1.ordNumber)(from([1, 2]), from([2, 3])), toArray, expect([2]).toEqual);
(0, pipeable_1.pipe)(intersection(Ord_1.ordNumber)(from([1, 2]), from([1, 2])), toArray, expect([1, 2]).toEqual);
});
it('difference', function () {
(0, pipeable_1.pipe)(difference(Ord_1.ordNumber)(from([1, 2]), from([3, 4])), toArray, expect([1, 2]).toEqual);
(0, pipeable_1.pipe)(difference(Ord_1.ordNumber)(from([1, 2]), from([2, 3])), toArray, expect([1]).toEqual);
(0, pipeable_1.pipe)(difference(Ord_1.ordNumber)(from([1, 2]), from([1, 2])), toArray, expect([]).toEqual);
});
it('reverse', function () {
(0, pipeable_1.pipe)([1, 2, 3], from, reverse, toArray, toEqual([3, 2, 1]));
});
it('reverse', function () {
(0, pipeable_1.pipe)(1, of, toArray, toEqual([1]));
});
it('foldLeft', function () {
var len = foldLeft(function () { return ',null'; }, function (_, tail) { return ',' + size(tail) + len(tail); });
expect(len(as)).toEqual(',2,1,0,null');
});
it('foldRight', function () {
var len = foldRight(function () { return 0; }, function (init, _) { return 1 + len(init); });
expect(len(as)).toEqual(3);
});
it('traverse', function () {
var tfanone = from([1, 2]);
var f = function (n) { return (n % 2 === 0 ? E.left(n) : E.right(n)); };
var result = traverse(E.either)(tfanone, f);
expect(E.isLeft(result)).toBeTruthy();
if (E.isLeft(result)) {
expect(result.left).toEqual(2);
}
var tfa = from([1, 3]);
var fas = traverse(E.either)(tfa, f);
expect(E.right(fas)).toBeTruthy();
if (E.isRight((fas))) {
expect(fas.right).toEqual(from([1, 3]));
}
});
it('traverseWithIndex', function () {
var tfanone = from([1, 2]);
var f = function (n) { return (n % 2 === 0 ? E.left(n) : E.right(n)); };
var result = traverseWithIndex(E.either)(tfanone, f);
expect(E.isLeft(result)).toBeTruthy();
if (E.isLeft(result)) {
expect(result.left).toEqual(0);
}
var tfa = from([1]);
var fas = traverseWithIndex(E.either)(tfa, f);
expect(E.right(fas)).toBeTruthy();
if (E.isRight((fas))) {
expect(fas.right).toEqual(from([1]));
}
});
it('sequence', function () {
var result = sequence(O.option)(from([O.some(1), O.some(3)]));
expect(O.isSome(result)).toBeTruthy();
if (O.isSome(result)) {
expect(result.value).toEqual(from([1, 3]));
}
expect(sequence(O.option)(from([O.some(1), O.none]))).toEqual(O.none);
});
it('wither', function () {
var witherIdentity = wither(I.identity);
var p = function (n) { return n > 2; };
var f = function (n) { return I.identity.of(p(n) ? O.some(n + 1) : O.none); };
expect(witherIdentity(empty(), f)).toEqual(I.identity.of(empty()));
expect(witherIdentity(from([1, 2, 3, 4]), f)).toEqual(I.identity.of(from([4, 5])));
});
it('wilt', function () {
var wiltIdentity = wilt(I.identity);
var p = function (n) { return n > 2; };
var f = function (n) { return I.identity.of(p(n) ? E.right(n + 1) : E.left(n - 1)); };
expect(wiltIdentity(empty(), f)).toEqual(I.identity.of({ left: empty(), right: empty() }));
expect(wiltIdentity(from([1, 2, 3, 4]), f)).toEqual(I.identity.of({ left: from([0, 1]), right: from([4, 5]) }));
});
it('extend', function () {
var sum = function (as) { return (0, Monoid_1.fold)(Monoid_1.monoidSum)(toArray(as)); };
(0, pipeable_1.pipe)(from([1, 2, 3, 4]), extend(sum), toArray, expect([10, 9, 7, 4]).toEqual);
(0, pipeable_1.pipe)(from([1, 2, 3, 4]), extend(function (a) { return a; }), toArray, expect([from([1, 2, 3, 4]), from([2, 3, 4]), from([3, 4]), from([4])]).toEqual);
});
it('duplicate', function () {
(0, pipeable_1.pipe)(from([1, 2, 3, 4]), duplicate, toArray, expect([from([1, 2, 3, 4]), from([2, 3, 4]), from([3, 4]), from([4])]).toEqual);
});
it('chop', function () {
var group = function (S) {
return chop(function (as) {
var _a = spanLeft(function (a) { return S.equals(a, _getAt(0)(as)); })(as), init = _a.init, rest = _a.rest;
return [init, rest];
});
};
expect(group(Eq_1.eqNumber)(from([1, 1, 2, 3, 3, 4]))).toEqual(from([from([1, 1]), from([2]), from([3, 3]), from([4])]));
expect(group(Eq_1.eqNumber)(from([1, 1, 2, 1, 1, 3, 3, 4]))).toEqual(from([from([1, 1]), from([2]), from([1, 1]), from([3, 3]), from([4])]));
});
it('groupByOption', function () {
(0, pipeable_1.pipe)(from([1, 1, 2, 1, 1, 3, 3, 4]), groupBy({ getValue: function (a) { return a; }, show: Show_1.showNumber }), expect({
'1': from([1, 1, 1, 1]),
'2': from([2]),
'3': from([3, 3]),
'4': from([4])
}).toEqual);
(0, pipeable_1.pipe)(from(basic_1.data), groupBy({ getValue: function (a) { return a.city ? a.city : 'newyork'; }, show: Show_1.showString }), function (v) { return expect(v).toMatchSnapshot(); });
});
it('comprehension', function () {
var result = comprehension([from(['a', 'b', 'c']), from(['eq', 'lt'])], function (a, b) { return a + '_' + b; });
expect(result).toEqual(from(["a_eq", "a_lt", "b_eq", "b_lt", "c_eq", "c_lt"]));
var result1 = comprehension([from(['a', 'b', 'c']), from(['eq', 'lt'])], function (a, b) { return a + '_' + b; }, function (a) { return a !== 'a'; });
expect(result1).toEqual(from(["b_eq", "b_lt", "c_eq", "c_lt"]));
});
it('fromRecord', function () {
(0, pipeable_1.pipe)({
a1: { b: 'b1' },
a2: { b: 'b2' },
a3: { b: 'b3' }
}, fromRecord('a'), toArray, function (as) { return expect(as).toEqual([{ a: 'a1', b: 'b1' }, { a: 'a2', b: 'b2' }, { a: 'a3', b: 'b3' }]); });
});
it('toRecord', function () {
(0, pipeable_1.pipe)([{ a: 'a1', b: 'b1', c: 'c1' }, { a: 'a2', b: 'b2', c: 'c1' }, { a: 'a3', b: 'b3', c: 'c1' }], from, toRecord('a'), function (as) { return expect(as).toEqual({
a1: { b: 'b1', c: 'c1' },
a2: { b: 'b2', c: 'c1' },
a3: { b: 'b3', c: 'c1' }
}); });
});
});
}
exports.default = test;
//# sourceMappingURL=Typeclass.js.map