Lazily Resolving Sequence
Genseq is sequence data structure that lazily consumes any iterable, including a generator, so that you can enjoy the benefits of both delayed evaluation, and the slicing and random access of lists.
The Genseq class implements the collections Sequence ABC, so the standard methods of using an immutable sequence are all available.
Install using Pip:
pip install genseq
Then wrap your generator with genseq:
>>> from genseq import genseq >>> @genseq ... def myiter(stop): ... for i in range(stop): ... yield i ... >>> myiter(5) 2 >>>
Or use the Genseq class on any iterable:
>>> from genseq import Genseq >>> Genseq(range(5)) 3 >>>