iterpy
Project description
iterpy
Python has implemented map
, filter
etc. as functions, rather than methods on a sequence. This makes the result harder to read and iterators less used than they could be. iterpy exists to change that.
You get this 🔥:
from iterpy import Iter
result = Iter([1,2,3]).map(multiply_by_2).filter(is_even)
Instead of this:
sequence = [1,2,3]
multiplied = [multiply_by_2(x) for x in sequence]
result = [x for x in multiplied if is_even(x)]
Or this:
result = filter(is_even, map(multiply_by_2, [1,2,3]))
Install
pip install iterpy
Usage
from iterpy import Iter
result = (Iter([1, 2])
.filter(lambda x: x % 2 == 0)
.map(lambda x: x * 2)
.to_list()
)
assert result == [4]
Prior art
iterpy stands on the shoulders of Scala, Rust etc.
Other Python projects have had similar ideas:
- PyFunctional has existed for 7+ years with a comprehensive feature set. It is performant, with built-in lineage and caching. Unfortunately, this makes typing non-trivial, with a 4+ year ongoing effort to add types.
- flupy is highly similar, well typed, and mature. I had some issues with
.flatten()
not being type-hinted correctly, but but your mileage may vary. - Your library here? Feel free to make an issue if you have a good alternative!
Contributing
Conventions
Philosophy
- Make it work: Concise syntax borrowed from Scala, Rust etc.
- Make it right: Fully typed, no exceptions
- Make it fast:
- Concurrency through
.pmap
- (Future): Caching
- (Future): Refactor operations to use generators
- Concurrency through
- Keep it simple: No dependencies
API design
As a heuristic, we follow the APIs of:
In cases where this conflicts with typical python implementations, the API should be as predictable as possible for Python users.
Devcontainer
- Install Orbstack or Docker Desktop. Make sure to complete the full install process before continuing.
- If not installed, install VSCode
- Press this link
- Complete the setup process
- Done! Easy as that.
💬 Where to ask questions
Type | |
---|---|
🚨 Bug Reports | GitHub Issue Tracker |
🎁 Feature Requests & Ideas | GitHub Issue Tracker |
👩💻 Usage Questions | GitHub Discussions |
🗯 General Discussion | GitHub Discussions |
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
iterpy-1.5.1.tar.gz
(35.2 kB
view details)
Built Distribution
iterpy-1.5.1-py3-none-any.whl
(10.7 kB
view details)
File details
Details for the file iterpy-1.5.1.tar.gz
.
File metadata
- Download URL: iterpy-1.5.1.tar.gz
- Upload date:
- Size: 35.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36ddf7b860a5257ab4eda40cb00075bc9f5cd664427c4334da8e63aa679ab54b |
|
MD5 | aca101d20782c05dc0f85b5a7db352ef |
|
BLAKE2b-256 | 3de45e762ef39fe10b9fa832f35757bd4458b6c313690b03fc61f0bfe48e021c |
File details
Details for the file iterpy-1.5.1-py3-none-any.whl
.
File metadata
- Download URL: iterpy-1.5.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 882bb3b0af1bafa080577283de74de5109528db7750121249a6dbcb4cda841e5 |
|
MD5 | 7a9b9219bf4acd77301b00e13c0f48ec |
|
BLAKE2b-256 | cbbb3e0cb5a6cc3ab48c94b2928f8f6ab894c9d55b8ec5ed6b5f6653e799184e |