Rust iterator utilities for Python
Project description
Rustiter
Rust-inspired iterator utilities for Python. This library implements most of the functions from the Rust Iterator trait.
Why
I'm a big fan of chaining function calls, but Python's functional programming tools can be cumbersome. No one really wants to use the built-in map
, filter
, and reduce
functions.
I previously experimented with simpleufcs, which allows for chainable function calls in Python.
This library offers an alternative: while it doesn't provide full UFCS (Uniform Function Call Syntax), it performs slightly better and brings many useful functions from Rust’s iterator design, such as take
, flat_map
, and more. If you're familiar with Rust and not too concerned about performance, you'll likely enjoy using this.
Installation
pip install rustiter
Example
Here are some commonly used functions:
from rustiter import rter
ret = (
rter(range(10))
.filter(lambda x: x % 2 == 0)
.map(lambda x: x + 1)
.take(3)
.collect()
)
assert ret == [1, 3, 5]
assert rter(range(10)).reduce(lambda x, y: x + y, 0) == 45
Additional Information: Every function includes a doctest to demonstrate its usage.
benchmark
Each data is in seconds. You can run bench.py manually.
Windows 11, python 3.12.7
bench | rustiter | builtin |
---|---|---|
1 | 0.21076 | 0.06355 |
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
File details
Details for the file rustiter-0.1.0.tar.gz
.
File metadata
- Download URL: rustiter-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.25
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a2baee302d57b9c17d47738943e79df25b33f4333971a829cd7a0da24fa47b5 |
|
MD5 | 68e2779ae0f152238d3485e6efd12c52 |
|
BLAKE2b-256 | 29c6cdd48998f9b1867c4ac80725495f3928c1aa19eadfde02d5da53983d40ac |
File details
Details for the file rustiter-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: rustiter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.25
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17d8d7cd3dd6cd928b8e6fd95b9060746d8fa27040c4fe423d120365a42d380d |
|
MD5 | 254d43734378c02d765eefc569e818c7 |
|
BLAKE2b-256 | b0b8d28d0a76a5f82a0148959b547313b636cd4b86531b2355be2ebbcd21dadb |