dankogai / js-combinatorics

power set, combination, permutation and more in JavaScript
MIT License
742 stars 97 forks source link

Allow serializing the iterators #13

Closed kewisch closed 9 years ago

kewisch commented 9 years ago

I'd like to save the state of the iterator to a file, so that I can continue iterating at that exact point on next run. A few values are held via closure, so I can't just serialize the iterator itself. Any ideas?

dankogai commented 9 years ago

You can save the seed array and its index then use .nth(index) to resume.

kewisch commented 9 years ago

Thanks, setting cp.index to the previous value seems to do it for the cartesian product!