Cache generator's results and reuse them
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reusegen-0.1.2.tar.gz.
File metadata
- Download URL: reusegen-0.1.2.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e9ce296f6be95ac1870672ea1ca35bb7579b462481a8d8ca845ea3494d3b512
|
|
| MD5 |
467e64265c1db675280aac1a012671bf
|
|
| BLAKE2b-256 |
81de40139896d8be12f491a521f1d20326795bcb2d4f9f5278b274160c58e6b4
|
File details
Details for the file reusegen-0.1.2-py3-none-any.whl.
File metadata
- Download URL: reusegen-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce693bd9bae0dfa2a27b6ddf570c33101b3e44002664e12aae0f98d4b30fea07
|
|
| MD5 |
743ba05e59702a2f12765d70a8ece6fc
|
|
| BLAKE2b-256 |
e900f885efd81d4296a643753383860d0e59fdebee4e7292f28b297413b924e4
|