Skip to main content

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

  • currprev
  • prevcurr
  • currnext
  • nextcurr
  • prevcurrnext
  • nextcurrprev

All functions have nearly the exact same parameters:

  • iterable: The iterable to process.
  • start_prev_on_none: Whether to yield None for the "previous" item before the first element. Default is True.
  • end_curr_on_none: Whether to yield None for the "current" item after the last element. Default is False.
  • end_next_on_none: Whether to yield None for the "next" item after the last element. Default is True.

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.

Metadata

Release files for prevcurrnext 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prevcurrnext 0.1.1
File Size Uploaded Provenance Actions
prevcurrnext-0.1.1.tar.gz 3.9 kB Without provenance Details for prevcurrnext-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prevcurrnext 0.1.1
File Interpreter ABI Platform Actions
prevcurrnext-0.1.1-py3-none-any.whl Python 3 none any Details for prevcurrnext-0.1.1-py3-none-any.whl

Total release size: 8.7 kB

Release files / prevcurrnext-0.1.1.tar.gz

Download URL prevcurrnext-0.1.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9d73e171f0272913f16a0a50c27073e20b6c8d8ed269a40abda69060e982405d
BLAKE2b-256 checksum
How to use checksums
cb319ae3e90b780c1600cfdf7318c8ee1c913da2ce963d68123136e7aaf3b4ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0

Release files / prevcurrnext-0.1.1-py3-none-any.whl

Download URL prevcurrnext-0.1.1-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee0a0de868dac4989d4aa8dd382d7c0f8dcea152c86e045d508bd63219bd7b8a
BLAKE2b-256 checksum
How to use checksums
b10173b33c414e1e2210c4cddc838defe599184923f165a90235cd6c5d58a8c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0

Security for prevcurrnext 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page