Skip to main content

Python package to create generator-like objects that can be iterated over more than once.

Project description

Repeatable

Python package to create generator-like objects that can be iterated over more than once.

Repeatable also provides itertools alternatives that handle thase iterables with far better memory efficients, even accepting infinite iterables.

Installation

pip install repeatable

Usage

Creating a repeatable Fibonacci-number generator:

from repeatable import repeatable

@repeatable
def fibonacci(max_value = 5):
    a, b, = 0, 1
    while a <= max_value:
        yield a
        a, b = b, a + b

repeatable_fibonacci = fibonacci()

for x in repeatable_fib:
    print(x)

repeatable_fibonacci.restart()

for y in repeatable_fib:
    print(y)

"""
0
1
1
2
3
5
0
1
1
2
3
5
"""

You can also use repeatable itertools on infinite generators:

from repeatable import repeatable, product

@repeatable
def fibonacci():
    a, b = 0, 1
    while True:
        yield a
        a, b = b, a + b

repeatable_fibonacci = fibonacci()

for p in product(repeatable_fibonacci, range(2)):
    print(p)

"""
(0, 0)
(0, 1)
(1, 0)
(1, 1)
(1, 0)
(1, 1)
(2, 0)
(2, 1)
(3, 0)
(3, 1)
(5, 0)
(5, 1)
...
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repeatable-0.0.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repeatable-0.0.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file repeatable-0.0.1.tar.gz.

File metadata

  • Download URL: repeatable-0.0.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for repeatable-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9e795d685fa04b41bf6a28af078745f862e2135d284ea51d549bd4046f39b994
MD5 defb0febc5e26654ac3ec74aa0c49102
BLAKE2b-256 f1e698f4d772e553f47c505406e53185172d002660216e5302f7315d617aa830

See more details on using hashes here.

File details

Details for the file repeatable-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: repeatable-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for repeatable-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7047a1cfcec85c37eb1a1dc6091e26936ed6e646e1881345f3b18afec1ea9b5b
MD5 adef47bcd1f0d2483727257cb316372e
BLAKE2b-256 076978340c6a989cc90bff6cbb3ecc19c24dd488e35cfe8e2c694db5a007038c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page