Name | rustiter JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | Rust iterator utilities for Python |
upload_time | 2024-10-24 08:37:49 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | None |
keywords |
iter
iterator
rust
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Rustiter
Rust-inspired iterator utilities for Python. This library implements **most of** the functions from the [Rust Iterator trait](https://doc.rust-lang.org/std/iter/trait.Iterator.html).
## 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](https://github.com/lxl66566/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
```sh
pip install rustiter
```
## Example
Here are some commonly used functions:
```py
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.
### Mutability
The mutability of Python's iterator is not ideal. Therefore, I marked the mutability of the functions as follows:
- `[Mut]`: The iterator may be modified after this operation. If there's not a `retains = ...`, the rest elements is undefined.
- `[UnMut]`: The iterator will not be modified.
- `[Consume]`: The iterator may be consumed after this operation. Note that this **does not** mean the iterator will become empty; there may still be elements in it. This means that you should not use this iterator again.
## benchmark
Windows 11, python 3.12.7
| Name (time in ns) | Min | Max | Mean | StdDev | Median | IQR | Outliers | OPS (Kops/s) | Rounds | Iterations |
| ----------------- | ----------------- | ------------------- | ----------------- | ------------------ | ----------------- | --------------- | ---------- | ---------------- | ------ | ---------- |
| test_normal | 524.9999 (1.0) | 26,137.4998 (1.0) | 600.2414 (1.0) | 247.7502 (1.0) | 575.0001 (1.0) | 37.5001 (1.0) | 2947;10025 | 1,665.9964 (1.0) | 169492 | 8 |
| test_rustiter | 1,399.9997 (2.67) | 251,400.0007 (9.62) | 1,669.7782 (2.78) | 2,722.4341 (10.99) | 1,599.9995 (2.78) | 100.0008 (2.67) | 107;1465 | 598.8819 (0.36) | 31646 | 1 |
Raw data
{
"_id": null,
"home_page": null,
"name": "rustiter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "iter, iterator, rust",
"author": null,
"author_email": "lxl66566 <lxl66566@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/8a/de/c74e1ca58ad20d910451fd4458226834943840013527a2c94893b11ee89a/rustiter-0.2.0.tar.gz",
"platform": null,
"description": "# Rustiter\n\nRust-inspired iterator utilities for Python. This library implements **most of** the functions from the [Rust Iterator trait](https://doc.rust-lang.org/std/iter/trait.Iterator.html).\n\n## Why\n\nI'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.\n\nI previously experimented with [simpleufcs](https://github.com/lxl66566/simpleufcs), which allows for chainable function calls in Python.\n\nThis 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\u2019s 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.\n\n## Installation\n\n```sh\npip install rustiter\n```\n\n## Example\n\nHere are some commonly used functions:\n\n```py\nfrom rustiter import rter\nret = (\n rter(range(10))\n .filter(lambda x: x % 2 == 0)\n .map(lambda x: x + 1)\n .take(3)\n .collect()\n)\nassert ret == [1, 3, 5]\nassert rter(range(10)).reduce(lambda x, y: x + y, 0) == 45\n```\n\nAdditional Information: **Every function** includes a doctest to demonstrate its usage.\n\n### Mutability\n\nThe mutability of Python's iterator is not ideal. Therefore, I marked the mutability of the functions as follows:\n\n- `[Mut]`: The iterator may be modified after this operation. If there's not a `retains = ...`, the rest elements is undefined.\n- `[UnMut]`: The iterator will not be modified.\n- `[Consume]`: The iterator may be consumed after this operation. Note that this **does not** mean the iterator will become empty; there may still be elements in it. This means that you should not use this iterator again.\n\n## benchmark\n\nWindows 11, python 3.12.7\n\n| Name (time in ns) | Min | Max | Mean | StdDev | Median | IQR | Outliers | OPS (Kops/s) | Rounds | Iterations |\n| ----------------- | ----------------- | ------------------- | ----------------- | ------------------ | ----------------- | --------------- | ---------- | ---------------- | ------ | ---------- |\n| test_normal | 524.9999 (1.0) | 26,137.4998 (1.0) | 600.2414 (1.0) | 247.7502 (1.0) | 575.0001 (1.0) | 37.5001 (1.0) | 2947;10025 | 1,665.9964 (1.0) | 169492 | 8 |\n| test_rustiter | 1,399.9997 (2.67) | 251,400.0007 (9.62) | 1,669.7782 (2.78) | 2,722.4341 (10.99) | 1,599.9995 (2.78) | 100.0008 (2.67) | 107;1465 | 598.8819 (0.36) | 31646 | 1 |\n",
"bugtrack_url": null,
"license": null,
"summary": "Rust iterator utilities for Python",
"version": "0.2.0",
"project_urls": {
"Homepage": "https://github.com/lxl66566/Rustiter",
"Repository": "https://github.com/lxl66566/Rustiter"
},
"split_keywords": [
"iter",
" iterator",
" rust"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2698b9a0c8334003d48207a7b754442f9ed2d88d62990861b3e03e85cd978059",
"md5": "42b9a74513105a14b4c80eb6249a19dc",
"sha256": "26019b3df51cfb91435a224516e5222c1567781e0197171d415e328bc5ecb088"
},
"downloads": -1,
"filename": "rustiter-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "42b9a74513105a14b4c80eb6249a19dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 9040,
"upload_time": "2024-10-24T08:37:47",
"upload_time_iso_8601": "2024-10-24T08:37:47.882489Z",
"url": "https://files.pythonhosted.org/packages/26/98/b9a0c8334003d48207a7b754442f9ed2d88d62990861b3e03e85cd978059/rustiter-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "8adec74e1ca58ad20d910451fd4458226834943840013527a2c94893b11ee89a",
"md5": "6d1c9eca82178fce2c975e037a85695e",
"sha256": "f44dcee818d2395466b3d1fc2c6a3be2e0a2bea086d0e12d992c518163fcad5e"
},
"downloads": -1,
"filename": "rustiter-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "6d1c9eca82178fce2c975e037a85695e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8650,
"upload_time": "2024-10-24T08:37:49",
"upload_time_iso_8601": "2024-10-24T08:37:49.035730Z",
"url": "https://files.pythonhosted.org/packages/8a/de/c74e1ca58ad20d910451fd4458226834943840013527a2c94893b11ee89a/rustiter-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-24 08:37:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lxl66566",
"github_project": "Rustiter",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "rustiter"
}