How to use iter-tools - 10 common examples

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 / subtypes / concrete / map.js View on Github external
constructor(iterable) {
    super(iterable);
    // prettier-ignore
    this.__native = new Map(
      iterable == null
        ? []
        : isCollection(iterable) || isNative(iterable)
          ? iterable.entries()
          : isPlainObj(iterable)
            ? entries(iterable)
            : iterable,
    );
  }
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);
    }
github conartist6 / sequins / src / sequence-keyed.js View on Github external
mapEntries(mapFn) {
    this.__transforms.push(map((entry, i) => mapFn(entry, i)));
    return this;
  }
github conartist6 / sequins / src / sequence-indexed.js View on Github external
*entries() {
    yield* map((value, i) => [i, value], this);
  }
}
github conartist6 / sequins / src / sequence-keyed.js View on Github external
mapKeys(mapFn) {
    this.__transforms.push(map(([key, value]) => [mapFn(key, value), value]));
    return this;
  }
github conartist6 / sequins / src / sequence-indexed.js View on Github external
map(mapFn) {
    this.__transforms.push(map(mapFn));
    return this;
  }
github conartist6 / sequins / src / sequence-set.js View on Github external
map(mapFn) {
    this.__transforms.push(map(item => mapFn(item)));
    return this;
  }
github conartist6 / sequins / src / sequence-keyed.js View on Github external
map(mapFn) {
    this.__transforms.push(map(([key, value]) => [key, mapFn(value, key)]));
    return this;
  }