extra-iterator 0.10.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -324,7 +324,7 @@ export declare class ExtraIterator<T> extends Iterator<T, any, any> {
324
324
  * .toArray()
325
325
  * // returns { even: [2, 4], odd: [1, 3, 5] }
326
326
  */
327
- groupBy<K extends string | symbol>(callbackfn: (value: T, index: number) => K): Record<K, T[]>;
327
+ groupBy<K extends string | symbol>(callbackfn: (value: T, index: number) => K): Partial<Record<K, T[]>>;
328
328
  /**
329
329
  * Groups elements into separate arrays and returns a Map containing each group.
330
330
  *
package/dist/index.js CHANGED
@@ -580,15 +580,7 @@ export class ExtraIterator extends Iterator {
580
580
  * // returns { even: [2, 4], odd: [1, 3, 5] }
581
581
  */
582
582
  groupBy(callbackfn) {
583
- const result = Object.create(null);
584
- for (let index = 0, next; next = this.next(), !next.done; index++) {
585
- const key = callbackfn(next.value, index);
586
- if (!result[key]) {
587
- result[key] = [];
588
- }
589
- result[key].push(next.value);
590
- }
591
- return result;
583
+ return this.collect(items => Object.groupBy(items, callbackfn));
592
584
  }
593
585
  /**
594
586
  * Groups elements into separate arrays and returns a Map containing each group.
@@ -600,26 +592,13 @@ export class ExtraIterator extends Iterator {
600
592
  * This method is similart to {@link groupBy}, but the returned object is a Map instead of a plain object.
601
593
  */
602
594
  toMap(callbackfn) {
603
- const result = new Map();
604
- for (let index = 0, next; next = this.next(), !next.done; index++) {
605
- const key = callbackfn(next.value, index);
606
- const array = result.get(key);
607
- if (!array) {
608
- result.set(key, [next.value]);
609
- }
610
- else {
611
- array.push(next.value);
612
- }
613
- }
614
- return result;
595
+ return this.collect(items => Map.groupBy(items, callbackfn));
615
596
  }
616
597
  /**
617
598
  * Creates a set containing all the values yielded by this iterator.
618
599
  */
619
600
  toSet() {
620
- const result = new Set();
621
- this.forEach(value => result.add(value));
622
- return result;
601
+ return new Set(this);
623
602
  }
624
603
  toChainOfResponsibilityFunction(invokeHandler) {
625
604
  const handlers = this.toArray();
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "An extension of the Iterator class with additional utility helper functions.",
4
4
  "author": "Leonardo Raele <leonardoraele@gmail.com>",
5
5
  "license": "MIT",
6
- "version": "0.10.2",
6
+ "version": "0.10.3",
7
7
  "type": "module",
8
8
  "exports": {
9
9
  ".": "./dist/index.js",