reduceplus


Namereduceplus JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/reduceplus
Summarylike functools.reduce but with exception handling, args and kwargs
upload_time2023-07-08 10:09:53
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords reduce
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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.

```python
    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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/reduceplus",
    "name": "reduceplus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "reduce",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bb/21/bda20f2c92623ed0c0571a4f3d2daa5872cca3572bc9d7d5ab93e83b8189/reduceplus-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# like functools.reduce but with exception handling, args and kwargs\r\n\r\n## pip install reduceplus \r\n\r\n## Example Usage\r\n\r\nThe function reduce_plus takes a function parameter, which should be a callable \r\nobject that accepts two arguments and performs a reduction operation.\r\n The sequence parameter is an iterable sequence of elements that will be reduced. \r\n The optional initial parameter provides an initial value for the reduction. \r\n If no initial value is provided and the sequence is empty, a TypeError is raised.\r\n\r\nThe args and kwargs parameters allow for additional positional and keyword arguments \r\nto be passed to the function. The ignore_exceptions parameter determines whether exceptions \r\nraised during the reduction process are ignored (True) or propagated (False). \r\nBy default, exceptions are ignored.\r\n\r\nThe function iterates over the sequence, using the initial value or the first \r\nelement as the starting point. For each element, the function is called with the \r\ncurrent value, the element, and any additional arguments and keyword arguments. \r\nIf an exception is raised during the reduction process and ignore_exceptions is \r\nFalse, the exception is propagated, terminating the reduction.\r\n\r\nFinally, the function returns the final reduced value.\r\n\r\n```python\r\n    Perform a reduction operation on a sequence using the specified function.\r\n\r\n    Args:\r\n        function: A callable object that takes two arguments and performs\r\n            a reduction operation.\r\n        sequence: An iterable sequence of elements to be reduced.\r\n        initial (optional): An initial value for the reduction. If not provided,\r\n            the first element of the sequence is used as the initial value.\r\n        / (slash): Separates positional-only arguments from positional or keyword arguments.\r\n        args (optional): Additional positional arguments to be passed to the function.\r\n        kwargs (optional): Additional keyword arguments to be passed to the function.\r\n        ignore_exceptions (optional): If True, exceptions raised during the reduction\r\n            process will be ignored and the reduction will continue. If False, the\r\n            exception will be propagated, terminating the reduction. Default is True.\r\n\r\n    Returns:\r\n        The final reduced value.\r\n\r\n    Raises:\r\n        TypeError: If the sequence is empty and no initial value is provided.\r\n\r\n    Examples:\r\n        from reduceplus import reduce_plus\r\n        ba = reduce_plus(\r\n        operator.add, [\"dddd\", 222, 434, \"dddds\"], 'xxxx', ignore_exceptions = True)\r\n        print(ba)\r\n        xxxxdddddddds\r\n\r\n        ba = reduce_plus(\r\n        operator.add, [\"dddd\", 222, 434, \"dddds\"], 20, ignore_exceptions = True)\r\n        print(ba)\r\n        676\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "like functools.reduce but with exception handling, args and kwargs",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/reduceplus"
    },
    "split_keywords": [
        "reduce"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "caf0a6fecab24beb91c64c4af1d8a4cc2f332bdf7209e6e108eb0a6e8e0b2f8f",
                "md5": "2106dbab76a900d7d2a2d28fb1df516a",
                "sha256": "a873519550b0438d69257aed032e3c747a2ec1cf4a10ab38b46d0b87a1462778"
            },
            "downloads": -1,
            "filename": "reduceplus-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2106dbab76a900d7d2a2d28fb1df516a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5375,
            "upload_time": "2023-07-08T10:09:50",
            "upload_time_iso_8601": "2023-07-08T10:09:50.915188Z",
            "url": "https://files.pythonhosted.org/packages/ca/f0/a6fecab24beb91c64c4af1d8a4cc2f332bdf7209e6e108eb0a6e8e0b2f8f/reduceplus-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bb21bda20f2c92623ed0c0571a4f3d2daa5872cca3572bc9d7d5ab93e83b8189",
                "md5": "8dad9e4cd49c856e55f0342a031e22b2",
                "sha256": "6dab32691d1ae74eec4e2bb41ad023254c0d6b535879ab96e126a99354b5030b"
            },
            "downloads": -1,
            "filename": "reduceplus-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "8dad9e4cd49c856e55f0342a031e22b2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3689,
            "upload_time": "2023-07-08T10:09:53",
            "upload_time_iso_8601": "2023-07-08T10:09:53.277148Z",
            "url": "https://files.pythonhosted.org/packages/bb/21/bda20f2c92623ed0c0571a4f3d2daa5872cca3572bc9d7d5ab93e83b8189/reduceplus-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-08 10:09:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "reduceplus",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "reduceplus"
}
        
Elapsed time: 0.22260s