sequins
Version:
Mutable sequences and native data structures (Map, Set, List) following the Immutable.js API
1,777 lines (1,521 loc) • 66.5 kB
JavaScript
import _possibleConstructorReturn from '@babel/runtime/helpers/esm/possibleConstructorReturn';
import _getPrototypeOf from '@babel/runtime/helpers/esm/getPrototypeOf';
import _inherits from '@babel/runtime/helpers/esm/inherits';
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
import _createClass from '@babel/runtime/helpers/esm/createClass';
import invariant from 'invariant';
import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray';
import concatIterables from 'iter-tools/es5/concat';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
import reduceIterable from 'iter-tools/es5/reduce';
import stable from 'stable';
import zipAllIterables from 'iter-tools/es5/zip-all';
import zipIterables from 'iter-tools/es5/zip';
import size from 'iter-tools/es5/size';
import _filter from 'iter-tools/es5/filter';
import keys from 'iter-tools/es5/keys';
import _slice from 'iter-tools/es5/slice';
import 'iter-tools/es5/compose';
import _get from '@babel/runtime/helpers/esm/get';
import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
import _map from 'iter-tools/es5/map';
import _tap from 'iter-tools/es5/tap';
import _interpose from 'iter-tools/es5/interpose';
import range from 'iter-tools/es5/range';
import entries from 'iter-tools/es5/entries';
import flat from 'iter-tools/es5/flat';
import repeat from 'iter-tools/es5/repeat';
function isImmutableCollection(shape) {
return !!shape['@@__IMMUTABLE_ITERABLE__@@'];
}
function isImmutableRecord(shape) {
return !!shape['@@__IMMUTABLE_RECORD__@@'];
}
function isImmutable(shape) {
return isImmutableCollection(shape) || isImmutableRecord(shape);
}
function isMutableCollection(shape) {
return !!shape['@@__MUTABLE_COLLECTION__@@'];
}
function isMutableSeq(shape) {
return !!shape['@@__MUTABLE_SEQUENCE__@@'];
}
function isCollection(shape) {
return isImmutableCollection(shape) || isMutableCollection(shape);
}
function isNative(shape) {
return isNativeKeyed(shape) || isNativeSet(shape);
} // Impl. borrowed from immutable, Copyright (c) 2014-present, Facebook, Inc.
function isPlainObj(shape) {
return !shape[Symbol.iterator] && shape.constructor === Object || shape.constructor === undefined;
}
function isDataStructure(shape) {
return isFancyDataStructure(shape) || isNative(shape) || Array.isArray(shape) || isPlainObj(shape);
}
function isFancyDataStructure(shape) {
return isMutableCollection(shape) || isImmutable(shape);
}
function isModernDataStructure(shape) {
return isFancyDataStructure(shape) || isNative(shape);
}
function isMutableConcreteish(shape) {
return !!shape['@@__MUTABLE_COLLECTION__@@'] && !shape['@@__MUTABLE_SEQUENCE__@@'];
}
function isMutableList(shape) {
return isMutableConcreteish(shape) && isMutableIndexed(shape);
}
function isMutableMap(shape) {
return isMutableConcreteish(shape) && isMutableKeyed(shape);
}
function isMutableSet(shape) {
return isMutableConcreteish(shape) && !isMutableAssociative(shape);
}
function isImmutableIndexed(shape) {
return !!shape['@@__IMMUTABLE_INDEXED__@@'];
}
function isImmutableKeyed(shape) {
return !!shape['@@__IMMUTABLE_KEYED__@@'];
}
function isNativeSet(shape) {
return shape instanceof Set;
}
function isNativeKeyed(shape) {
return shape instanceof Map;
}
function isMutableIndexed(shape) {
return !!shape['@@__MUTABLE_INDEXED__@@'];
}
function isMutableKeyed(shape) {
return !!shape['@@__MUTABLE_KEYED__@@'];
}
function isMutableAssociative(shape) {
return isMutableIndexed(shape) || isMutableKeyed(shape);
}
function isIndexed(shape) {
return Array.isArray(shape) || isMutableIndexed(shape) || isImmutableIndexed(shape);
}
function isKeyed(shape) {
return isNativeKeyed(shape) || isMutableKeyed(shape) || isImmutableKeyed(shape);
}
var Namespace =
/*#__PURE__*/
function () {
function Namespace() {
_classCallCheck(this, Namespace);
}
_createClass(Namespace, [{
key: "__get",
value: function __get(key) {
var _key = "_".concat(key);
invariant(this.hasOwnProperty(_key), 'Tried to access member %s of %s, but no such member was registered yet. The module include order was likely wrong.', key, this.__description);
return this[_key];
}
}, {
key: "__description",
get: function get() {
return 'namespace';
}
}]);
return Namespace;
}();
var RootNamespace =
/*#__PURE__*/
function (_Namespace) {
_inherits(RootNamespace, _Namespace);
function RootNamespace() {
_classCallCheck(this, RootNamespace);
return _possibleConstructorReturn(this, _getPrototypeOf(RootNamespace).apply(this, arguments));
}
_createClass(RootNamespace, [{
key: "__register",
value: function __register(collectionType, NestedNamespace) {
return this["_".concat(collectionType)] = NestedNamespace;
}
}, {
key: "__description",
get: function get() {
return 'the root namespace';
}
}, {
key: "Concrete",
get: function get() {
return this.__get('Concrete');
}
}, {
key: "Sequence",
get: function get() {
return this.__get('Sequence');
}
}]);
return RootNamespace;
}(Namespace);
var SubtypeNamespace =
/*#__PURE__*/
function (_Namespace2) {
_inherits(SubtypeNamespace, _Namespace2);
function SubtypeNamespace() {
_classCallCheck(this, SubtypeNamespace);
return _possibleConstructorReturn(this, _getPrototypeOf(SubtypeNamespace).apply(this, arguments));
}
_createClass(SubtypeNamespace, [{
key: "__register",
value: function __register(collectionSubtype, CollectionConstructor) {
return this["_".concat(collectionSubtype)] = CollectionConstructor;
}
}, {
key: "Duplicated",
get: function get() {
return this.__get('Duplicated');
}
}, {
key: "Indexed",
get: function get() {
return this.__get('Indexed');
}
}, {
key: "Keyed",
get: function get() {
return this.__get('Keyed');
}
}]);
return SubtypeNamespace;
}(Namespace);
function makeKey(collectionSubtype, collectionType) {
return "".concat(collectionSubtype, "__").concat(collectionType);
}
function memoizeFactory(factory) {
var results = Object.create(null);
return function memoizedFactory(Collection) {
for (var _len = arguments.length, dynamicArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
dynamicArgs[_key - 1] = arguments[_key];
}
var key = makeKey.apply(void 0, dynamicArgs);
if (!results[key]) {
results[key] = factory.apply(void 0, [Collection].concat(dynamicArgs));
}
return results[key];
};
}
function makeConcat(Collection, collectionType, collectionSubtype) {
var SequenceConstructor = Collection.Sequence[collectionSubtype];
return function concat(iterable) {
for (var _len = arguments.length, iterables = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
iterables[_key - 1] = arguments[_key];
}
return concatIterables.apply(void 0, [iterable].concat(_toConsumableArray(iterables.map(function (iterable) {
return new SequenceConstructor(iterable);
}))));
};
}
var concat$1 = memoizeFactory(makeConcat);
var reflect = Object.freeze({
Duplicated: {
NativeConstructor: Set,
itemValue: function itemValue(item) {
return item;
},
primitiveIterator: function primitiveIterator(collection) {
return collection.values();
}
},
Indexed: {
NativeConstructor: Array,
itemValue: function itemValue(item) {
return item;
},
primitiveIterator: function primitiveIterator(collection) {
return collection.values();
}
},
Keyed: {
NativeConstructor: Map,
itemValue: function itemValue(item) {
return item[1];
},
primitiveIterator: function primitiveIterator(collection) {
return collection.entries();
}
}
});
function makeFlatten(Collection, collectionType$$1, collectionSubtype) {
var _reflect$collectionSu = reflect[collectionSubtype],
itemValue = _reflect$collectionSu.itemValue,
primitiveIterator = _reflect$collectionSu.primitiveIterator;
return (
/*#__PURE__*/
_regeneratorRuntime.mark(function flatten(iterable) {
var shallowOrDepth,
depth,
_iteratorNormalCompletion,
_didIteratorError,
_iteratorError,
_iterator,
_step,
item,
value,
_args = arguments;
return _regeneratorRuntime.wrap(function flatten$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
shallowOrDepth = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
depth = Number(shallowOrDepth);
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 5;
_iterator = iterable[Symbol.iterator]();
case 7:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context.next = 23;
break;
}
item = _step.value;
value = itemValue(item);
if (!(!value || !isMutableCollection(value))) {
_context.next = 15;
break;
}
_context.next = 13;
return item;
case 13:
_context.next = 20;
break;
case 15:
if (!(depth !== 1)) {
_context.next = 19;
break;
}
return _context.delegateYield(flatten(primitiveIterator(value), depth === 0 ? 0 : depth - 1), "t0", 17);
case 17:
_context.next = 20;
break;
case 19:
return _context.delegateYield(primitiveIterator(value), "t1", 20);
case 20:
_iteratorNormalCompletion = true;
_context.next = 7;
break;
case 23:
_context.next = 29;
break;
case 25:
_context.prev = 25;
_context.t2 = _context["catch"](5);
_didIteratorError = true;
_iteratorError = _context.t2;
case 29:
_context.prev = 29;
_context.prev = 30;
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
case 32:
_context.prev = 32;
if (!_didIteratorError) {
_context.next = 35;
break;
}
throw _iteratorError;
case 35:
return _context.finish(32);
case 36:
return _context.finish(29);
case 37:
case "end":
return _context.stop();
}
}
}, flatten, this, [[5, 25, 29, 37], [30,, 32, 36]]);
})
);
}
var flatten = memoizeFactory(makeFlatten);
function makePush(Collection, collectionType, collectionSubtype) {
if (collectionSubtype === 'Indexed') {
return function (collection, _, value) {
return collection.push(value);
};
} else if (collectionSubtype === 'Keyed') {
return function (collection, key, value) {
return collection.set(key, value);
};
} else {
return function (collection, _, value) {
return collection.add(value);
};
}
}
var makePush$1 = memoizeFactory(makePush);
var reduceByType = {
Duplicated: function reduce(iterable, reducer, initial) {
var setReducer = function setReducer(acc, item) {
return reducer(acc, item, item);
};
var reduced;
if (arguments.length > 2) {
reduced = reduceIterable(initial, setReducer, iterable);
} else {
reduced = reduceIterable(setReducer, iterable);
}
return reduced;
},
Indexed: function reduce(iterable, reducer, initial) {
var reduced;
if (arguments.length > 2) {
reduced = reduceIterable(initial, reducer, iterable);
} else {
reduced = reduceIterable(reducer, iterable);
}
return reduced;
},
Keyed: function reduce(iterable, reducer, initial) {
var invocations = 0;
var hasInitial = arguments.length > 2;
var reduced;
var keyedReducer = function keyedReducer(acc, _ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
if (invocations++ === 0 && !hasInitial) {
acc = acc[1];
}
return reducer(acc, value, key);
};
if (hasInitial) {
reduced = reduceIterable(initial, keyedReducer, iterable);
} else {
reduced = reduceIterable(keyedReducer, iterable);
}
return reduced;
}
};
function makeReduce(Collection, collectionType, collectionSubtype) {
return reduceByType[collectionSubtype];
}
function makeGroupBy(Collection, collectionType, collectionSubtype) {
var concreteType = collectionType === 'Sequence' ? 'Concrete' : collectionType;
var CollectionConstructor = Collection[collectionType][collectionSubtype];
var ConcreteCollectionConstructor = Collection[concreteType][collectionSubtype];
var Map = Collection.Concrete.Keyed;
var push = makePush$1.apply(void 0, arguments);
var reduce = makeReduce.apply(void 0, arguments);
return function groupBy(collection, grouper) {
var map = reduce(collection, function (result, value, key) {
var groupKey = grouper(value, key);
if (!result.get(groupKey)) {
var concrete = new ConcreteCollectionConstructor();
result.set(groupKey, concrete);
}
push(result.get(groupKey), key, value);
return result;
}, new Map());
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = map.keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
map.set(key, new CollectionConstructor(map.get(key)));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return map;
};
}
var groupBy = memoizeFactory(makeGroupBy);
function ensureArray(iterable) {
return Array.isArray(iterable) ? iterable : Array.from(iterable);
}
var defaultComparator = function defaultComparator(a, b) {
return a > b ? 1 : a < b ? -1 : 0;
};
function makeSort(Collection, collectionType, collectionSubtype) {
var _reflect$collectionSu = reflect[collectionSubtype],
itemValue = _reflect$collectionSu.itemValue,
NativeConstructor = _reflect$collectionSu.NativeConstructor;
return function sort(inPlace, iterable, selector) {
var comparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : defaultComparator;
var array = ensureArray(iterable);
var wrappedComparator = selector ? function (a, b) {
return comparator(selector(itemValue(a)), selector(itemValue(b)));
} : function (a, b) {
return comparator(itemValue(a), itemValue(b));
};
if (inPlace) {
stable.inplace(array, wrappedComparator);
} else {
array = stable(array, wrappedComparator);
}
if (collectionType === 'Sequence' || collectionSubtype === 'Indexed') {
return array;
}
return new NativeConstructor(array);
};
}
var sort = memoizeFactory(makeSort);
function makeToConcrete(Collection, collectionType, collectionSubtype) {
var ConcreteConstructor = Collection.Concrete[collectionSubtype];
return function toNative(value) {
return new ConcreteConstructor(value);
};
}
var toConcrete = memoizeFactory(makeToConcrete);
function makeToJS(Collection) {
return function toJS(value) {
return isDataStructure(value) ? Collection.Sequence.from(value).map(toJS).toJSON() : value;
};
}
var toJs = memoizeFactory(makeToJS);
function makeZipAll(Collection, collectionType, collectionSubtype) {
var SequenceConstructor = Collection.Sequence[collectionSubtype];
return function zipAll(iterable) {
for (var _len = arguments.length, iterables = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
iterables[_key - 1] = arguments[_key];
}
return zipAllIterables.apply(void 0, [iterable].concat(_toConsumableArray(iterables.map(function (iterable) {
return new SequenceConstructor(iterable);
}))));
};
}
var zipAll = memoizeFactory(makeZipAll);
function makeZip(Collection, collectionType, collectionSubtype) {
var SequenceConstructor = Collection.Sequence[collectionSubtype];
return function zip(iterable) {
for (var _len = arguments.length, iterables = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
iterables[_key - 1] = arguments[_key];
}
return zipIterables.apply(void 0, [iterable].concat(_toConsumableArray(iterables.map(function (iterable) {
return new SequenceConstructor(iterable);
}))));
};
}
var zip = memoizeFactory(makeZip);
var factories = /*#__PURE__*/Object.freeze({
concat: concat$1,
flatten: flatten,
groupBy: groupBy,
reduce: makeReduce,
sort: sort,
toConcrete: toConcrete,
toJS: toJs,
zipAll: zipAll,
zip: zip
});
var Namespace$1 = new RootNamespace();
var Collection = Namespace$1;
var emptyArray = [];
var MethodFactory = function MethodFactory(collectionType, collectionSubtype) {
_classCallCheck(this, MethodFactory);
this._collectionType = collectionType;
this._collectionSubtype = collectionSubtype;
};
var nativeFactories = new Map([[Map, function (coll) {
return new Map(new Collection.Sequence.Keyed(coll));
}], [Set, function (coll) {
return new Set(new Collection.Sequence.Duplicated(coll));
}], [Array, function (coll) {
return Array.from(new Collection.Sequence.Indexed(coll));
}], [Object, // TODO use Object.fromEntries here when it is ready.
function (coll) {
return new Collection.Sequence.Keyed(coll).reduce(function (obj, value, key) {
obj[key] = value;
return obj;
}, {});
}]]);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var _loop = function _loop() {
var name = _step.value;
Object.defineProperty(MethodFactory.prototype, name, {
get: function get() {
return factories[name](Collection, this._collectionType, this._collectionSubtype);
}
});
};
for (var _iterator = keys(factories)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var CollectionMixin = function CollectionMixin(Base) {
var CollectionMixin =
/*#__PURE__*/
function (_Base) {
_inherits(CollectionMixin, _Base);
function CollectionMixin(iterable, collectionType, collectionSubtype) {
var _this;
_classCallCheck(this, CollectionMixin);
_this = _possibleConstructorReturn(this, _getPrototypeOf(CollectionMixin).call(this, iterable, collectionSubtype));
_this.__selfParam = emptyArray;
_this.__dynamicMethods = new MethodFactory(collectionType, collectionSubtype);
return _this;
}
_createClass(CollectionMixin, [{
key: "slice",
value: function slice() {
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
return this.__doCollectionTransform(_slice({
start: start,
end: end
}));
}
}, {
key: "concat",
value: function concat() {
var _this2 = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return this.__doCollectionTransform(function (iterable) {
var _this2$__dynamicMetho;
return (_this2$__dynamicMetho = _this2.__dynamicMethods).concat.apply(_this2$__dynamicMetho, [iterable].concat(args));
});
}
}, {
key: "flatten",
value: function flatten$$1() {
var _this3 = this;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return this.__doCollectionTransform(function (iterable) {
var _this3$__dynamicMetho;
return (_this3$__dynamicMetho = _this3.__dynamicMethods).flatten.apply(_this3$__dynamicMetho, [iterable].concat(args));
});
}
}, {
key: "groupBy",
value: function groupBy$$1(grouper) {
var _this4 = this;
return this.__doCollectionTransform(function (iterable) {
return _this4.__dynamicMethods.groupBy(iterable, grouper);
});
}
}, {
key: "flatMap",
value: function flatMap(mapFn) {
return this.map(mapFn).flatten(true);
}
}, {
key: "sort",
value: function sort$$1() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return this.sortBy.apply(this, [null].concat(args));
}
}, {
key: "count",
value: function count(predicate) {
return size(predicate ? this.filter(predicate) : this);
} // Reductive functions
}, {
key: "reduce",
value: function reduce(reducer) {
var _this5 = this;
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
args[_key4 - 1] = arguments[_key4];
}
return this.__doReductiveTransform(function (iterable) {
var _this5$__dynamicMetho;
return (_this5$__dynamicMetho = _this5.__dynamicMethods).reduce.apply(_this5$__dynamicMetho, [iterable, function (acc, value, index) {
return reducer.apply(void 0, [acc, value, index].concat(_toConsumableArray(_this5.__selfParam)));
}].concat(args));
});
} // Deep conversions
}, {
key: "toJS",
value: function toJS() {
return this.__dynamicMethods.toJS(this);
} // Shallow conversions
}, {
key: "toSeq",
value: function toSeq() {
return new Collection.Sequence.from(this);
}
}, {
key: "toConcrete",
value: function toConcrete$$1() {
return this.__dynamicMethods.toConcrete(this);
}
}, {
key: "to",
value: function to(CollectionConstructor) {
if (nativeFactories.has(CollectionConstructor)) {
return nativeFactories.get(CollectionConstructor)(this);
} else {
return this instanceof CollectionConstructor ? this : new CollectionConstructor(this);
}
}
}]);
return CollectionMixin;
}(Base);
Object.defineProperty(CollectionMixin.prototype, '@@__MUTABLE_COLLECTION__@@', {
value: true
});
return CollectionMixin;
};
var Collection$1 = CollectionMixin(function SequinsBase() {
_classCallCheck(this, SequinsBase);
});
var emptyArray$1 = [];
function makeFrom(Collection, collectionType$$1) {
var TypedCollection = Collection[collectionType$$1];
return function from(initial) {
if (initial == null) {
return new TypedCollection.Indexed(emptyArray$1);
} else if (isCollection(initial) || isNative(initial)) {
if (isIndexed(initial)) {
return new TypedCollection.Indexed(initial);
} else if (isKeyed(initial)) {
return new TypedCollection.Keyed(initial);
} else {
return new TypedCollection.Duplicated(initial);
}
} else if (typeof initial[Symbol.iterator] === 'function') {
return new TypedCollection.Indexed(initial);
} else if (isPlainObj(initial)) {
return new TypedCollection.Keyed(initial);
}
return null;
};
}
var makeFrom$1 = memoizeFactory(makeFrom);
var SequenceNamespace =
/*#__PURE__*/
function (_SubtypeNamespace) {
_inherits(SequenceNamespace, _SubtypeNamespace);
function SequenceNamespace() {
_classCallCheck(this, SequenceNamespace);
return _possibleConstructorReturn(this, _getPrototypeOf(SequenceNamespace).apply(this, arguments));
}
_createClass(SequenceNamespace, [{
key: "from",
value: function from(initial) {
return sequenceFrom(initial);
}
}]);
return SequenceNamespace;
}(SubtypeNamespace);
var Namespace$2 = Namespace$1.__register('Sequence', new SequenceNamespace());
var sequenceFrom = makeFrom$1(Namespace$1, 'Sequence');
var identityFn = function identityFn(_) {
return _;
};
var Sequence =
/*#__PURE__*/
function (_Collection) {
_inherits(Sequence, _Collection);
_createClass(Sequence, null, [{
key: "from",
value: function from(initial) {
return sequenceFrom(initial);
}
}]);
function Sequence(iterable, collectionSubtype) {
var _this;
_classCallCheck(this, Sequence);
iterable = iterable || [];
_this = _possibleConstructorReturn(this, _getPrototypeOf(Sequence).call(this, iterable, 'Sequence', collectionSubtype));
_this.__iterable = iterable;
_this.__transform = null;
_this.__constructorTransform = null;
return _this;
}
_createClass(Sequence, [{
key: "__doCollectionTransform",
value: function __doCollectionTransform(transform) {
var Sequence = this[Symbol.species]();
var result = new Sequence(this);
result.__transform = transform;
return result;
}
}, {
key: "__doReductiveTransform",
value: function __doReductiveTransform(transform) {
return transform(this._transform());
}
}, {
key: "_transform",
value: function _transform() {
var constructorTransform = this.__constructorTransform || identityFn;
var transform = this.__transform || identityFn;
return transform(constructorTransform(this.__iterable));
}
}, {
key: Symbol.iterator,
value: function value() {
return this._transform()[Symbol.iterator]();
}
}, {
key: "set",
value: function set(key, newValue) {
return this.map(function (value, key) {
return key === key ? newValue : value;
});
}
}, {
key: "push",
value: function push(key, newValue) {
return this.concat([newValue]);
}
}, {
key: "delete",
value: function _delete(key) {
return this.filter(function (_, key) {
return key !== key;
});
}
}, {
key: "groupBy",
value: function groupBy(grouper) {
var _this2 = this;
var concrete = this.toConcrete();
var keyed = new Namespace$2.Keyed(concrete);
keyed.__transform = function () {
return _this2.__dynamicMethods.groupBy(concrete, grouper);
};
return keyed;
}
}, {
key: "reverse",
value: function reverse() {
return this.__doCollectionTransform(function (iterable) {
return Array.from(iterable).reverse();
});
}
}, {
key: "sortBy",
value: function sortBy() {
var _this3 = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return this.__doCollectionTransform(function (iterable) {
var _this3$__dynamicMetho;
return (_this3$__dynamicMetho = _this3.__dynamicMethods).sort.apply(_this3$__dynamicMetho, [false, iterable].concat(args));
});
}
}]);
return Sequence;
}(Collection$1);
Object.defineProperty(Sequence.prototype, '@@__MUTABLE_SEQUENCE__@@', {
value: true
});
var Namespace$3 = Namespace$1.__register('Concrete', new SubtypeNamespace());
var concreteFrom = makeFrom$1(Collection$1, 'Concrete');
var ConcreteCollection =
/*#__PURE__*/
function (_Collection) {
_inherits(ConcreteCollection, _Collection);
function ConcreteCollection(iterable, collectionSubtype) {
var _this;
_classCallCheck(this, ConcreteCollection);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ConcreteCollection).call(this, iterable, 'Concrete', collectionSubtype));
_this.__selfParam = [_assertThisInitialized(_assertThisInitialized(_this))];
return _this;
}
_createClass(ConcreteCollection, [{
key: "__doCollectionTransform",
value: function __doCollectionTransform(transform) {
var CollectionConstructor = this.constructor;
var transformed = transform(this.__native);
if (transformed instanceof ConcreteCollection) {
return transformed;
} else {
var coll = new CollectionConstructor();
coll.__native = this.__constructNative(transformed);
return coll;
}
}
}, {
key: "__constructNative",
value: function __constructNative(iterable) {
var NativeConstructor = this.__native.constructor;
return new NativeConstructor(iterable);
}
}, {
key: "__doReductiveTransform",
value: function __doReductiveTransform(transform) {
return transform(this.__native);
}
}, {
key: "count",
value: function count(predicate) {
return predicate ? _get(_getPrototypeOf(ConcreteCollection.prototype), "count", this).call(this, predicate) : this.size;
}
}, {
key: "get",
value: function get(key, defaultValue) {
return this.has(key) ? this.__native.get(key) : defaultValue;
}
}, {
key: "has",
value: function has(key) {
return this.__native.has(key);
}
}, {
key: "delete",
value: function _delete(key) {
return this.__native.delete(key);
}
}, {
key: "clear",
value: function clear() {
var NativeConstructor = this.__native.constructor;
this.__native = new NativeConstructor();
return this;
}
}, {
key: "isEmpty",
value: function isEmpty() {
return this.size === 0;
}
}, {
key: "concat",
value: function (_concat) {
function concat() {
return _concat.apply(this, arguments);
}
concat.toString = function () {
return _concat.toString();
};
return concat;
}(function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return this.__doCollectionTransform(function (iterable) {
return concat.apply(void 0, [iterable].concat(args));
});
})
}, {
key: "__reverse",
value: function __reverse() {
var reversedSeq = Namespace$1.Sequence.from(this).reverse().toConcrete();
this.clear();
return reversedSeq;
}
}, {
key: "toConcrete",
value: function toConcrete() {
return this;
} // Iterators
}, {
key: "keys",
value: function keys$$1() {
return new Namespace$1.Sequence.Duplicated(this.__native.keys());
}
}, {
key: "values",
value: function values() {
return new Namespace$1.Sequence.Duplicated(this.__native.values());
}
}, {
key: "entries",
value: function entries$$1() {
return new Namespace$1.Sequence.Duplicated(this.__native.entries());
}
}, {
key: Symbol.iterator,
value: function value() {
return this.__native[Symbol.iterator]();
}
}, {
key: "size",
get: function get() {
return this.__native.size;
}
}], [{
key: "from",
value: function from(initial) {
return concreteFrom(initial);
}
}]);
return ConcreteCollection;
}(Collection$1);
function forEach(func, iterable) {
var c = 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = iterable[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var item = _step.value;
func(item, c++);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return iterable;
}
function forSome(func, iterable) {
var c = 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = iterable[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var item = _step.value;
var ret = func(item, c++);
if (ret === false) {
break;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return c;
}
var DuplicatedMixin = (function (Base) {
return (
/*#__PURE__*/
function (_Base) {
_inherits(SetCollection, _Base);
function SetCollection(iterable) {
_classCallCheck(this, SetCollection);
return _possibleConstructorReturn(this, _getPrototypeOf(SetCollection).call(this, iterable, 'Duplicated'));
} // Collection functions
_createClass(SetCollection, [{
key: "map",
value: function map(mapFn) {
var _this = this;
return this.__doCollectionTransform(_map(function (item) {
return mapFn.apply(void 0, [item, item].concat(_toConsumableArray(_this.__selfParam)));
}));
}
}, {
key: "tap",
value: function tap(tapFn) {
var _this2 = this;
return this.__doCollectionTransform(_tap(function (item) {
return tapFn.apply(void 0, [item, item].concat(_toConsumableArray(_this2.__selfParam)));
}));
}
}, {
key: "filter",
value: function filter(filterFn) {
var _this3 = this;
return this.__doCollectionTransform(_filter(function (item) {
return filterFn.apply(void 0, [item, item].concat(_toConsumableArray(_this3.__selfParam)));
}));
}
}, {
key: "filterNot",
value: function filterNot(filterFn) {
var _this4 = this;
return this.__doCollectionTransform(_filter(function (item) {
return !filterFn.apply(void 0, [item, item].concat(_toConsumableArray(_this4.__selfParam)));
}));
} // Reductive functions
}, {
key: "forEach",
value: function forEach$$1(eachFn) {
var _this5 = this;
forEach(function (item) {
return eachFn.apply(void 0, [item, item].concat(_toConsumableArray(_this5.__selfParam)));
}, this);
}
}, {
key: "forSome",
value: function forSome$$1(eachFn) {
var _this6 = this;
return forSome(function (item) {
return eachFn.apply(void 0, [item, item].concat(_toConsumableArray(_this6.__selfParam)));
}, this);
} // Conversions
}, {
key: "toJSON",
value: function toJSON() {
return this.to(Array);
}
}]);
return SetCollection;
}(Base)
);
});
var IndexedMixin = (function (Base) {
var IndexedCollection =
/*#__PURE__*/
function (_Base) {
_inherits(IndexedCollection, _Base);
function IndexedCollection(iterable) {
_classCallCheck(this, IndexedCollection);
return _possibleConstructorReturn(this, _getPrototypeOf(IndexedCollection).call(this, iterable, 'Indexed'));
} // prettier-ignore
_createClass(IndexedCollection, [{
key: "zip",
value: function zip() {
var _this = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return this.__doCollectionTransform(function (iterable) {
var _this$__dynamicMethod;
return (_this$__dynamicMethod = _this.__dynamicMethods).zip.apply(_this$__dynamicMethod, [iterable].concat(args));
});
}
}, {
key: "zipAll",
value: function zipAll() {
var _this2 = this;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return this.__doCollectionTransform(function (iterable) {
var _this2$__dynamicMetho;
return (_this2$__dynamicMetho = _this2.__dynamicMethods).zipAll.apply(_this2$__dynamicMetho, [iterable].concat(args));
});
}
}, {
key: "zipWith",
value: function zipWith(zipper) {
var _this3 = this;
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key3 - 1] = arguments[_key3];
}
return this.__doCollectionTransform(function (iterable) {
var _this3$__dynamicMetho;
return _map(function (items) {
return zipper.apply(void 0, _toConsumableArray(items));
}, (_this3$__dynamicMetho = _this3.__dynamicMethods).zip.apply(_this3$__dynamicMetho, [iterable].concat(args)));
});
}
}, {
key: "interpose",
value: function interpose(separator) {
return this.__doCollectionTransform(_interpose(separator));
} // Collection functions
}, {
key: "map",
value: function map(mapFn) {
var _this4 = this;
return this.__doCollectionTransform(_map(function (value, i) {
return mapFn.apply(void 0, [value, i].concat(_toConsumableArray(_this4.__selfParam)));
}));
}
}, {
key: "tap",
value: function tap(tapFn) {
var _this5 = this;
return this.__doCollectionTransform(_tap(function (value, i) {
return tapFn.apply(void 0, [value, i].concat(_toConsumableArray(_this5.__selfParam)));
}));
}
}, {
key: "filter",
value: function filter(filterFn) {
var _this6 = this;
return this.__doCollectionTransform(_filter(function (value, i) {
return filterFn.apply(void 0, [value, i].concat(_toConsumableArray(_this6.__selfParam)));
}));
}
}, {
key: "filterNot",
value: function filterNot(filterFn) {
var _this7 = this;
return this.__doCollectionTransform(_filter(function (value, i) {
return !filterFn.apply(void 0, [value, i].concat(_toConsumableArray(_this7.__selfParam)));
}));
} // Reductive functions
}, {
key: "forEach",
value: function forEach$$1(eachFn) {
var _this8 = this;
forEach(function (value, i) {
return eachFn.apply(void 0, [value, i].concat(_toConsumableArray(_this8.__selfParam)));
}, this);
}
}, {
key: "forSome",
value: function forSome$$1(eachFn) {
var _this9 = this;
return forSome(function (value, i) {
return eachFn.apply(void 0, [value, i].concat(_toConsumableArray(_this9.__selfParam)));
}, this);
} // Conversions
}, {
key: "toJSON",
value: function toJSON() {
return this.to(Array);
}
}]);
return IndexedCollection;
}(Base);
Object.defineProperty(IndexedCollection.prototype, '@@__MUTABLE_INDEXED__@@', {
value: true
});
return IndexedCollection;
});
var KeyedMixin = (function (Base) {
var KeyedCollection =
/*#__PURE__*/
function (_Base) {
_inherits(KeyedCollection, _Base);
function KeyedCollection(iterable) {
_classCallCheck(this, KeyedCollection);
return _possibleConstructorReturn(this, _getPrototypeOf(KeyedCollection).call(this, iterable, 'Keyed'));
}
_createClass(KeyedCollection, [{
key: "flip",
value: function flip() {
return this.__doCollectionTransform(_map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return [value, key];
}));
} // Collection functions
}, {
key: "map",
value: function map(mapFn) {
var _this = this;
return this.__doCollectionTransform(_map(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
key = _ref4[0],
value = _ref4[1];
return [key, mapFn.apply(void 0, [value, key].concat(_toConsumableArray(_this.__selfParam)))];
}));
}
}, {
key: "mapKeys",
value: function mapKeys(mapFn) {
var _this2 = this;
return this.__doCollectionTransform(_map(function (_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
key = _ref6[0],
value = _ref6[1];
return [mapFn.apply(void 0, [key, value].concat(_toConsumableArray(_this2.__selfParam))), value];
}));
}
}, {
key: "mapEntries",
value: function mapEntries(mapFn) {
var _this3 = this;
return this.__doCollectionTransform(_map(function (entry, i) {
return mapFn.apply(void 0, [entry, i].concat(_toConsumableArray(_this3.__selfParam)));
}));
}
}, {
key: "tap",
value: function tap(tapFn) {
var _this4 = this;
return this.__doCollectionTransform(_tap(function (_ref7) {
var _ref8 = _slicedToArray(_ref7, 2),
key = _ref8[0],
value = _ref8[1];
return tapFn.apply(void 0, [value, key].concat(_toConsumableArray(_this4.__selfParam)));
}));
}
}, {
key: "filter",
value: function filter(filterFn) {
var _this5 = this;
return this.__doCollectionTransform(_filter(function (_ref9) {
var _ref10 = _slicedToArray(_ref9, 2),
key = _ref10[0],
value = _ref10[1];
return filterFn.apply(void 0, [value, key].concat(_toConsumableArray(_this5.__selfParam)));
}));
}
}, {
key: "filterNot",
value: function filterNot(filterFn) {
var _this6 = this;
return this.__doCollectionTransform(_filter(function (_ref11) {
var _ref12 = _slicedToArray(_ref11, 2),
key = _ref12[0],
value = _ref12[1];
return !filterFn.apply(void 0, [value, key].concat(_toConsumableArray(_this6.__selfParam)));
}));
} // Reductive functions
}, {
key: "forEach",
value: function forEach$$1(eachFn) {
var _this7 = this;
forEach(function (_ref13) {
var _ref14 = _slicedToArray(_ref13, 2),
key = _ref14[0],
value = _ref14[1];
return eachFn.apply(void 0, [value, key].concat(_toConsumableArray(_this7.__selfParam)));
}, this);
}
}, {
key: "forSome",
value: function forSome$$1(eachFn) {
var _this8 = this;
return forSome(function (_ref15) {
var _ref16 = _slicedToArray(_ref15, 2),
key = _ref16[0],
value = _ref16[1];
return eachFn.apply(void 0, [value, key].concat(_toConsumableArray(_this8.__selfParam)));
}, this);
} // Conversions
}, {
key: "toJSON",
value: function toJSON() {
return this.to(Object);
}
}]);
return KeyedCollection;
}(Base);
Object.defineProperty(KeyedCollection.prototype, '@@__MUTABLE_KEYED__@@', {
value: true
});
return KeyedCollection;
});
var _marked =
/*#__PURE__*/
_regeneratorRuntime.mark(arrayEntries);
function arrayEntries(array) {
var i;
return _regeneratorRuntime.wrap(function arrayEntries$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
i = 0;
case 1:
if (!(i < array.length)) {
_context.next = 7;
break;
}
_context.next = 4;
return [i, array[i]];
case 4:
i++;
_context.next = 1;
break;
case 7:
case "end":
return _context.stop();
}
}
}, _marked, this);
}
var List =
/*#__PURE__*/
function (_IndexedMixin) {
_inherits(List, _IndexedMixin);
_createClass(List, null, [{
key: "isList",
value: function isList(shape) {
return isMutableList(shape);
}
}, {
key: "of",
value: function of() {
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
values[_key] = arguments[_key];
}
return new List(values);
}
}]);
function List(iterable) {
var _this;
_classCallCheck(this, List);
_this = _possibleConstructorReturn(this, _getPrototypeOf(List).call(this, iterable));
_this.__native = iterable == null ? [] : Array.from(isKeyed(iterable) ? iterable.values() : iterable);
return _this;
}
_createClass(List, [{
key: "__constructNative",
value: function __constructNative(iterable) {
return Array.from(iterable);
}
}, {
key: "get",
value: function get(idx) {
return this.__native[idx];
}
}, {
key: "set",
value: function set(idx, value) {
this.__native[idx] = value;
return this;
}
}, {
key: "has",
value: function has(idx) {
return idx < this.__native.length;
}
}, {
key: "push",
value: function push() {
var _this$__native;
(_this$__native = this.__native).push.apply(_this$__native, arguments);
return this;
}
}, {
key: "pop",
value: function pop() {
return this.__native.pop();
}
}, {
key: "shift",
value: function shift() {
return this.__native.shift();
}
}, {
key: "unshift",
value: function unshift(value) {
this.__native.unshift(value);
return this;
}
}, {
key: "first",
value: function first() {
return this.__native[0];
}
}, {
key: "last",
value: function last() {
return this.__native[this.__native.length];
}
}, {
key: "sortBy",
value: function sortBy() {
var _this$__dynamicMethod;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
(_this$__dynamicMethod = this.__dynamicMethods).sort.apply(_this$__dynamicMethod, [true, this.__native].concat(args));
return this;
}
}, {
key: "fill",
value: function fill() {
var _this$__native2;
(_this$__native2 = this.__native).fill.apply(_this$__native2, arguments);
return this;
}
}, {
key: "includes",
value: function includes(value) {
return this.__native.includes(value);
}
}, {
key: "map",
value: function map(mapFn) {
var _this2 = this;
return this.__doCollectionTransform(function () {
return _this2.__native.map(function (value, index) {
return mapFn(value, index, _this2);
});
});
}
}, {
key: "filter",
value: function filter(filterFn) {
var _this3 = this;
return this.__doCollectionTransform(function () {
return _this3.__native.filter(function (value, index) {
return filterFn(value, index, _this3);
});
});
}
}, {
key: "filterNot",
value: function filterNot(filterFn) {
var _this4 = this;
return this.__doCollectionTransform(function () {
return _this4.__native.filter(function (value, index) {
return !filterFn(value, index, _this4);
});
});
}
}, {
key: "slice",
value: function slice() {
var _this5 = this;
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return this.__doCollectionTransform(function () {
var _this5$__native;
return (_this5$__native = _this5.__native).slice.apply(_this5$__native, args);
});
}
}, {
key: "concat",
value: function concat() {
var _this6 = this;
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return this.__doCollectionTransform(function () {
var _this6$__native;
return (_this6$__native = _this6.__native).concat.apply(_this6$__native, args);
});
}
}, {
key: "reverse",
value: function reverse() {
this.__native.reverse();
return this;
}
}, {
key: "reduce",
value: function reduce(reducer) {
var _this$__native3,
_this7 = this;
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
args[_key5 - 1] = arguments[_key5];
}
return (_this$__native3 = this.__native).reduce.apply(_this$__native3, [function (acc, value, index) {
return reducer(acc, value, index, _this7);
}].concat(args));
}
}, {
key: "join",
value: function join(sepa