extra-iterator 0.9.0 → 0.9.1
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.js +1 -1
- package/dist/index.test.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -137,7 +137,7 @@ export class ExtraIterator extends Iterator {
|
|
|
137
137
|
* @example ExtraIterator.from([[1, 2], [3, 4]]).flatten().toArray() // returns [1, 2, 3, 4]
|
|
138
138
|
*/
|
|
139
139
|
flatten() {
|
|
140
|
-
return this.flatMap(value => value);
|
|
140
|
+
return this.flatMap(value => Array.isArray(value) ? new ExtraIterator(value).flatten() : [value]);
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* Creates a new iterator that yields the values of this iterator, but won't yield any duplicates.
|
package/dist/index.test.js
CHANGED
|
@@ -47,8 +47,8 @@ describe('ExtraIterator', () => {
|
|
|
47
47
|
expect(iterator.toArray()).toEqual([3, 4]);
|
|
48
48
|
});
|
|
49
49
|
it('should flatten nested iterables', () => {
|
|
50
|
-
const iterator = ExtraIterator.from([[1, 2
|
|
51
|
-
expect(iterator.toArray()).toEqual([1, 2, 3, 4]);
|
|
50
|
+
const iterator = ExtraIterator.from([0, [1, [2, [3, 4]]], [5, [6]], 7]).flatten();
|
|
51
|
+
expect(iterator.toArray()).toEqual([0, 1, 2, 3, 4, 5, 6, 7]);
|
|
52
52
|
});
|
|
53
53
|
it('should return the first value', () => {
|
|
54
54
|
const iterator = ExtraIterator.from([1, 2, 3]);
|
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.9.
|
|
6
|
+
"version": "0.9.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./dist/index.js",
|