How to use the iter-tools/es5/keys function in iter-tools

To help you get started, we’ve selected a few iter-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github conartist6 / sequins / src / collection.js View on Github external
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);
    }