Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const nativeFactories = new Map([
[Map, coll => new Map(new Collection.Sequence.Keyed(coll))],
[Set, coll => new Set(new Collection.Sequence.Duplicated(coll))],
[Array, coll => Array.from(new Collection.Sequence.Indexed(coll))],
[
Object,
// TODO use Object.fromEntries here when it is ready.
coll =>
new Collection.Sequence.Keyed(coll).reduce((obj, value, key) => {
obj[key] = value;
return obj;
}, {}),
],
]);
for (const name of keys(factories)) {
Object.defineProperty(MethodFactory.prototype, name, {
get() {
return factories[name](Collection, this._collectionType, this._collectionSubtype);
},
});
}
export const CollectionMixin = Base => {
class CollectionMixin extends Base {
constructor(iterable, collectionType, collectionSubtype) {
super(iterable, collectionSubtype);
this.__selfParam = emptyArray;
this.__dynamicMethods = new MethodFactory(collectionType, collectionSubtype);
}