Iteration utils for "prev", "curr", and "next"-style for-loops.
Project description
prevcurrnext
Iteration utils for "prev", "curr", and "next"-style for-loops.
Install
pip install prevcurrnext
Usage
The prevcurrnext function yields pairs of consecutive elements from an iterable, allowing you to see the "previous", "current", and "next" items for each element. It includes options to yield None at the beginning and/or end of the sequence for convenient boundary handling.
from prevcurrnext import prevcurr, currnext, prevcurrnext
# Basic usage
for prev, curr in prevcurr([1, 2, 3]):
print(prev, curr)
# Output:
# None 1
# 1 2
# 2 3
# Customizing boundary behavior
# Adding None at the end
for prev, curr in prevcurr([1, 2, 3], end_curr_on_none=True):
print(prev, curr)
# Output:
# None 1
# 1 2
# 2 3
# 3 None
for curr, _next in currnext([1, 2, 3]):
print(curr, _next)
# Output:
# 1 2
# 2 3
# 3 None
for prev, curr, _next in prevcurrnext([1, 2, 3]):
print(prev, curr, _next)
# Output:
# None 1 2
# 1 2 3
# 2 3 None
Available functions
currprevprevcurrcurrnextnextcurrprevcurrnextnextcurrprev
All functions have nearly the exact same parameters:
iterable: The iterable to process.start_prev_on_none: Whether to yieldNonefor the "previous" item before the first element. Default isTrue.end_curr_on_none: Whether to yieldNonefor the "current" item after the last element. Default isFalse.end_next_on_none: Whether to yieldNonefor the "next" item after the last element. Default isTrue.
Contributing
Contributions are welcome! If you find issues or have suggestions, please open an issue or submit a pull request on GitHub.
Development Setup
If you use Poetry
poetry install
poetry run pytest
Otherwise...
python -m venv venv
source venv/bin/activate
pip install -r requirements-dev.txt
pip install -e .
pytest
License
This project is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prevcurrnext-0.1.1.tar.gz.
File metadata
- Download URL: prevcurrnext-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d73e171f0272913f16a0a50c27073e20b6c8d8ed269a40abda69060e982405d
|
|
| MD5 |
390114a3f6b8310af6d6c6959d5e4000
|
|
| BLAKE2b-256 |
cb319ae3e90b780c1600cfdf7318c8ee1c913da2ce963d68123136e7aaf3b4ac
|
File details
Details for the file prevcurrnext-0.1.1-py3-none-any.whl.
File metadata
- Download URL: prevcurrnext-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee0a0de868dac4989d4aa8dd382d7c0f8dcea152c86e045d508bd63219bd7b8a
|
|
| MD5 |
86d3e4929cd909ee7d0e27a2591694e9
|
|
| BLAKE2b-256 |
b10173b33c414e1e2210c4cddc838defe599184923f165a90235cd6c5d58a8c7
|