reusegen
Generators are exhausted during iteration:
xs = (x * x for x in range(10))
ys = [x + 1 for x in xs] # [1, 2, ...]
zs = [x + 2 for x in xs] # []
Sometimes this is not expected. With reusegen, you can reuse generators like lists:
from reusegen import reuse
xs = reuse(x * x for x in range(10))
ys = [x + 1 for x in xs]
zs = [x + 1 for x in xs]
print(ys == zs) # True
And it also works as decorator:
@reuse
def double(xs):
for x in xs:
yield x * 2
By default, the results of generator is cached. You could make it cacheless to save memory as original generator:
xs = reuse(x * x for x in range(10), cache=False)
The generator will be executed multiple times.
TODO
Add cacheless version of reuse.
Release files for reusegen 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| reusegen-0.1.2.tar.gz | 2.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| reusegen-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.0 kB
Release files / reusegen-0.1.2.tar.gz
| Download URL | reusegen-0.1.2.tar.gz |
|---|---|
| Size | 2.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e9ce296f6be95ac1870672ea1ca35bb7579b462481a8d8ca845ea3494d3b512
|
|
BLAKE2b-256 checksum How to use checksums |
81de40139896d8be12f491a521f1d20326795bcb2d4f9f5278b274160c58e6b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Release files / reusegen-0.1.2-py3-none-any.whl
| Download URL | reusegen-0.1.2-py3-none-any.whl |
|---|---|
| Size | 3.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce693bd9bae0dfa2a27b6ddf570c33101b3e44002664e12aae0f98d4b30fea07
|
|
BLAKE2b-256 checksum How to use checksums |
e900f885efd81d4296a643753383860d0e59fdebee4e7292f28b297413b924e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|