chainit
Documentation available here: https://lukapeschke.github.io/chainit/
This library provides the ChainIt class, a wrapper around stdlib's
itertools module, allowing to chain
operations on iterables, resulting in easier-to-read code.
import typing as t
def fib() -> t.Iterable[int]:
a, b = 0, 1
while True:
yield a
a, b = b, a + b
# Allows to write things like this...
(
ChainIt(fib())
.filter(lambda x: x % 2 == 0)
.map(lambda x: x // 2)
.flat_map(range)
.take_while(lambda x: x < 6)
.collect_list()
)
# ...rather than like this
from itertools import chain as ichain, islice, takewhile
list(
takewhile(
lambda x: x < 6,
ichain.from_iterable(
map(lambda x: range(x // 2), filter(lambda x: x % 2 == 0, fib()))
),
)
)
Installation
pip install chainit
Examples
Decorator
In addition to ChainIt, the library provides a chainit decorator. It makes a function returning
an iterable return a ChainIt instead:
@chainit
def fac():
n = 0
fac = 1
while True:
yield fac
n += 1
fac *= n
assert fac().enumerate().take(5).collect() == ((0, 1), (1, 1), (2, 2), (3, 6), (4, 24))
Using a ChainIt instance as an iterable
assert list(fac().take(3)) == [1, 1, 2]
for idx, x in fac().enumerate():
if idx > 3:
break
print(x)
Metadata
Release files for chainit 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chainit-0.5.0.tar.gz | 3.7 kB | Without provenance | Details for chainit-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chainit-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for chainit-0.5.0-py3-none-any.whl |
Total release size: 8.7 kB
Release files / chainit-0.5.0.tar.gz
| Download URL | chainit-0.5.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10aebe64b5cb49260e960946e48a8e52d665f83a2fc9d7c93c6c39df404af5af
|
|
BLAKE2b-256 checksum How to use checksums |
1a381e2b43f08976dfe7dd37fd8ed586ad3fa349633cee356fffb46216dd2b2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / chainit-0.5.0-py3-none-any.whl
| Download URL | chainit-0.5.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f128881eb24cece989738b7965729bc85c83256ba1523b3b6969a31eb0002ddb
|
|
BLAKE2b-256 checksum How to use checksums |
cb062bed4db1eb6960f1e5ab95923d2b8ca2af065a31b0a030a31c1d17369927
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for chainit 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.