Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seq.rest() throws an exception when invoked on a single item sequence #1220

Closed
olivr70 opened this issue May 3, 2017 · 1 comment
Closed

Comments

@olivr70
Copy link

olivr70 commented May 3, 2017

I am using the version 4.0.0-rc.2

What happened

An exception was thrown at Iterator.next() (immutable.js line 1496)

How to reproduce

var r = Seq(['a']).rest()
var x = [...r] // throws 'TypeError: iterator.next is not a function'

This also occurs with multiple items in the sequence, on the last iteration when invoking .rest() (or .slice(1)) several times

@olivr70
Copy link
Author

olivr70 commented May 5, 2017

As a temporary quick and dirty solution, I patched line 1491 of immutable.js (method sliceSeq.__iteratorUncached)

var iterator = sliceSize !== 0 && collection.__iterator(type, reverse);

to

    var iterator = sliceSize !== 0 ? collection.__iterator(type, reverse)
      : emptySequence()[Symbol.iterator]()

There is certainly a better solution to return an empty sequence, that's why I did not PR

olivr70 pushed a commit to olivr70/immutable-js that referenced this issue May 14, 2017
olivr70 pushed a commit to olivr70/immutable-js that referenced this issue May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants