Skip to main content

like functools.reduce but with exception handling, args and kwargs

pip install reduceplus

Example Usage

The function reduce_plus takes a function parameter, which should be a callable object that accepts two arguments and performs a reduction operation. The sequence parameter is an iterable sequence of elements that will be reduced. The optional initial parameter provides an initial value for the reduction. If no initial value is provided and the sequence is empty, a TypeError is raised.

The args and kwargs parameters allow for additional positional and keyword arguments to be passed to the function. The ignore_exceptions parameter determines whether exceptions raised during the reduction process are ignored (True) or propagated (False). By default, exceptions are ignored.

The function iterates over the sequence, using the initial value or the first element as the starting point. For each element, the function is called with the current value, the element, and any additional arguments and keyword arguments. If an exception is raised during the reduction process and ignore_exceptions is False, the exception is propagated, terminating the reduction.

Finally, the function returns the final reduced value.

    Perform a reduction operation on a sequence using the specified function.

    Args:
        function: A callable object that takes two arguments and performs
            a reduction operation.
        sequence: An iterable sequence of elements to be reduced.
        initial (optional): An initial value for the reduction. If not provided,
            the first element of the sequence is used as the initial value.
        / (slash): Separates positional-only arguments from positional or keyword arguments.
        args (optional): Additional positional arguments to be passed to the function.
        kwargs (optional): Additional keyword arguments to be passed to the function.
        ignore_exceptions (optional): If True, exceptions raised during the reduction
            process will be ignored and the reduction will continue. If False, the
            exception will be propagated, terminating the reduction. Default is True.

    Returns:
        The final reduced value.

    Raises:
        TypeError: If the sequence is empty and no initial value is provided.

    Examples:
        from reduceplus import reduce_plus
        ba = reduce_plus(
        operator.add, ["dddd", 222, 434, "dddds"], 'xxxx', ignore_exceptions = True)
        print(ba)
        xxxxdddddddds

        ba = reduce_plus(
        operator.add, ["dddd", 222, 434, "dddds"], 20, ignore_exceptions = True)
        print(ba)
        676

Metadata

Release files for reduceplus 0.10

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

Source distribution (sdist)

Source distribution for reduceplus 0.10
File Size Uploaded Provenance Actions
reduceplus-0.10.tar.gz 3.7 kB Without provenance Details for reduceplus-0.10.tar.gz

Built distribution (wheel)

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

Total release size: 9.1 kB

Release files / reduceplus-0.10.tar.gz

Download URL reduceplus-0.10.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6dab32691d1ae74eec4e2bb41ad023254c0d6b535879ab96e126a99354b5030b
BLAKE2b-256 checksum
How to use checksums
bb21bda20f2c92623ed0c0571a4f3d2daa5872cca3572bc9d7d5ab93e83b8189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / reduceplus-0.10-py3-none-any.whl

Download URL reduceplus-0.10-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a873519550b0438d69257aed032e3c747a2ec1cf4a10ab38b46d0b87a1462778
BLAKE2b-256 checksum
How to use checksums
caf0a6fecab24beb91c64c4af1d8a4cc2f332bdf7209e6e108eb0a6e8e0b2f8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for reduceplus 0.10

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.10 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