Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4e0f50

Browse filesBrowse files
conartist6leebyron
authored andcommitted
[BREAKING] Remove IteratorSequence. Do not attempt to detect iterators. (#1589)
Fixes #1456
1 parent e65e5af commit f4e0f50
Copy full SHA for f4e0f50

File tree

Expand file treeCollapse file tree

4 files changed

+21
-263
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+21
-263
lines changed

‎__tests__/IterableSeq.ts

Copy file name to clipboardExpand all lines: __tests__/IterableSeq.ts
-200Lines changed: 0 additions & 200 deletions
This file was deleted.

‎__tests__/Seq.ts

Copy file name to clipboardExpand all lines: __tests__/Seq.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ describe('Seq', () => {
2222
expect(Seq({ a: 1, b: 2, c: 3 }).size).toBe(3);
2323
});
2424

25+
it('accepts an object with a next property', () => {
26+
expect(Seq({ a: 1, b: 2, next: _ => _ }).size).toBe(3);
27+
});
28+
2529
it('accepts a collection string', () => {
2630
expect(Seq('foo').size).toBe(3);
2731
});

‎src/Seq.js

Copy file name to clipboardExpand all lines: src/Seq.js
+6-59Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -288,55 +288,6 @@ class CollectionSeq extends IndexedSeq {
288288
}
289289
}
290290

291-
class IteratorSeq extends IndexedSeq {
292-
constructor(iterator) {
293-
this._iterator = iterator;
294-
this._iteratorCache = [];
295-
}
296-
297-
__iterateUncached(fn, reverse) {
298-
if (reverse) {
299-
return this.cacheResult().__iterate(fn, reverse);
300-
}
301-
const iterator = this._iterator;
302-
const cache = this._iteratorCache;
303-
let iterations = 0;
304-
while (iterations < cache.length) {
305-
if (fn(cache[iterations], iterations++, this) === false) {
306-
return iterations;
307-
}
308-
}
309-
let step;
310-
while (!(step = iterator.next()).done) {
311-
const val = step.value;
312-
cache[iterations] = val;
313-
if (fn(val, iterations++, this) === false) {
314-
break;
315-
}
316-
}
317-
return iterations;
318-
}
319-
320-
__iteratorUncached(type, reverse) {
321-
if (reverse) {
322-
return this.cacheResult().__iterator(type, reverse);
323-
}
324-
const iterator = this._iterator;
325-
const cache = this._iteratorCache;
326-
let iterations = 0;
327-
return new Iterator(() => {
328-
if (iterations >= cache.length) {
329-
const step = iterator.next();
330-
if (step.done) {
331-
return step;
332-
}
333-
cache[iterations] = step.value;
334-
}
335-
return iteratorValue(type, iterations, cache[iterations++]);
336-
});
337-
}
338-
}
339-
340291
// # pragma Helper functions
341292

342293
export function isSeq(maybeSeq) {
@@ -352,11 +303,9 @@ function emptySequence() {
352303
export function keyedSeqFromValue(value) {
353304
const seq = Array.isArray(value)
354305
? new ArraySeq(value)
355-
: isIterator(value)
356-
? new IteratorSeq(value)
357-
: hasIterator(value)
358-
? new CollectionSeq(value)
359-
: undefined;
306+
: hasIterator(value)
307+
? new CollectionSeq(value)
308+
: undefined;
360309
if (seq) {
361310
return seq.fromEntrySeq();
362311
}
@@ -395,9 +344,7 @@ function seqFromValue(value) {
395344
function maybeIndexedSeqFromValue(value) {
396345
return isArrayLike(value)
397346
? new ArraySeq(value)
398-
: isIterator(value)
399-
? new IteratorSeq(value)
400-
: hasIterator(value)
401-
? new CollectionSeq(value)
402-
: undefined;
347+
: hasIterator(value)
348+
? new CollectionSeq(value)
349+
: undefined;
403350
}

‎type-definitions/Immutable.d.ts

Copy file name to clipboardExpand all lines: type-definitions/Immutable.d.ts
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,10 +3008,13 @@ declare module Immutable {
30083008
* * If a `Seq`, that same `Seq`.
30093009
* * If an `Collection`, a `Seq` of the same kind (Keyed, Indexed, or Set).
30103010
* * If an Array-like, an `Seq.Indexed`.
3011-
* * If an Object with an Iterator, an `Seq.Indexed`.
3012-
* * If an Iterator, an `Seq.Indexed`.
3011+
* * If an Iterable Object, an `Seq.Indexed`.
30133012
* * If an Object, a `Seq.Keyed`.
30143013
*
3014+
* Note: An Iterator itself will be treated as an object, becoming a `Seq.Keyed`,
3015+
* which is usually not what you want. You should turn your Iterator Object into
3016+
* an iterable object by defining a Symbol.iterator (or @@iterator) method which
3017+
* returns `this`.
30153018
*/
30163019
export function Seq<S extends Seq<any, any>>(seq: S): S;
30173020
export function Seq<K, V>(collection: Collection.Keyed<K, V>): Seq.Keyed<K, V>;
@@ -3723,13 +3726,17 @@ declare module Immutable {
37233726
*
37243727
* * If an `Collection`, that same `Collection`.
37253728
* * If an Array-like, an `Collection.Indexed`.
3726-
* * If an Object with an Iterator, an `Collection.Indexed`.
3727-
* * If an Iterator, an `Collection.Indexed`.
3729+
* * If an Object with an Iterator defined, an `Collection.Indexed`.
37283730
* * If an Object, an `Collection.Keyed`.
37293731
*
37303732
* This methods forces the conversion of Objects and Strings to Collections.
37313733
* If you want to ensure that a Collection of one item is returned, use
37323734
* `Seq.of`.
3735+
*
3736+
* Note: An Iterator itself will be treated as an object, becoming a `Seq.Keyed`,
3737+
* which is usually not what you want. You should turn your Iterator Object into
3738+
* an iterable object by defining a Symbol.iterator (or @@iterator) method which
3739+
* returns `this`.
37333740
*/
37343741
export function Collection<I extends Collection<any, any>>(collection: I): I;
37353742
export function Collection<T>(collection: Iterable<T>): Collection.Indexed<T>;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.