pyfunctional-elunico


Namepyfunctional-elunico JSON
Version 0.16.0 PyPI version JSON
download
home_pagehttps://github.com/elunico/pyfunctional
SummaryA small collection of functions I find useful
upload_time2023-04-11 22:24:50
maintainer
docs_urlNone
authorThomas Povinelli
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyfunctional

Find it [on PyPI](https://pypi.org/project/pyfunctional-elunico/)

This is a collection of functional tools I like to use in Python

## Contents

```python
def alleq(iterable: Iterable[S]) -> bool
```

returns True if an iterable is empty or if all elements are equal to the first

---

```python
def transpose(double_iterable: Iterable[Iterable[S]])
```

an iterable object that takes a nested iterable and transposes it lazily

---

```python
def repeat(element: E, count: int)
```

an iterable object that takes an element and a count and returns that element `count` times

---

```python
def attempt(
  block: Callable[[Any], T],
  default: T = None,
  catch: Union[Type[Exception], Iterable[Type[Exception]]] = (Exception,),
  args: Iterable[Any],
  kwargs: Dict[Any, Any]
) -> T
```

a function that takes a callable, a default value, a list of excpetion types, an arg tuple, and a kwarg dict and calls the callable, catching the exceptions specified, and returning the function value on success, the default value on a known caught exception, and allowing any other none-accounted for exceptions bubble up.

---

```python
def rreduce(
    reduction: Callable[[R, E], R],
    indexable: Indexable,
    initvalue: Union[R, Sentinel] = sentinel
) -> R
```

Performs the same operation as `functools.reduce` but working from the right side (high indices) of the collection rather than the start (lower indices) of the collection. Requires the collection to support `len()` and indexing (iterators do not support `__getitem__` but lists and tuples--for example--do)

Not the specification for `Indexable` below

```python
from typing import Protocol

class Indexable(Protocol):
  def __getitem__(self, index: int) -> Any: ...
  def __len__(self) -> int: ...
```

---

```python
def commute(fn: Callable[[S, T], R]) -> Callable[[T, S], R]
```

Commutes the operands of a binary function. Does not (yet) work for varargs or functions other than 2-arity

---

```python
def identity(x: T) -> T
```

The identity function

---

```python
def bind(fn: Callable[[Any], R], arg: Any, position: int = 0) -> Callable[[Any], R]
```

Given a `n`-arity function `fn`, bind `arg` to the `position`th argument of `fn` and return a new function which takes `n-1` args. The new function behaves as if the positional argument at `posititon` was removed from the argument order.

The argument count is 0 based

If `fn.__code__.co_argcount` is less or equal to `posititon` the function will raise a `ValueError`

---

```python
def full(fn: Callable[[Any], R], *args: Any) -> Callable[[], R]
```

Like functools.partial, except requires you to fill in **all** the arguments of `fn`. Returns a new function
that passes `*args` to `fn` but takes no arguments itself and returns the return value of `fn`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/elunico/pyfunctional",
    "name": "pyfunctional-elunico",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Thomas Povinelli",
    "author_email": "tompov227@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3e/57/b76f63f4aee5f3e8c24ab9648165ebdeea95926301e0a4076ad9937637b1/pyfunctional-elunico-0.16.0.tar.gz",
    "platform": null,
    "description": "# pyfunctional\n\nFind it [on PyPI](https://pypi.org/project/pyfunctional-elunico/)\n\nThis is a collection of functional tools I like to use in Python\n\n## Contents\n\n```python\ndef alleq(iterable: Iterable[S]) -> bool\n```\n\nreturns True if an iterable is empty or if all elements are equal to the first\n\n---\n\n```python\ndef transpose(double_iterable: Iterable[Iterable[S]])\n```\n\nan iterable object that takes a nested iterable and transposes it lazily\n\n---\n\n```python\ndef repeat(element: E, count: int)\n```\n\nan iterable object that takes an element and a count and returns that element `count` times\n\n---\n\n```python\ndef attempt(\n  block: Callable[[Any], T],\n  default: T = None,\n  catch: Union[Type[Exception], Iterable[Type[Exception]]] = (Exception,),\n  args: Iterable[Any],\n  kwargs: Dict[Any, Any]\n) -> T\n```\n\na function that takes a callable, a default value, a list of excpetion types, an arg tuple, and a kwarg dict and calls the callable, catching the exceptions specified, and returning the function value on success, the default value on a known caught exception, and allowing any other none-accounted for exceptions bubble up.\n\n---\n\n```python\ndef rreduce(\n    reduction: Callable[[R, E], R],\n    indexable: Indexable,\n    initvalue: Union[R, Sentinel] = sentinel\n) -> R\n```\n\nPerforms the same operation as `functools.reduce` but working from the right side (high indices) of the collection rather than the start (lower indices) of the collection. Requires the collection to support `len()` and indexing (iterators do not support `__getitem__` but lists and tuples--for example--do)\n\nNot the specification for `Indexable` below\n\n```python\nfrom typing import Protocol\n\nclass Indexable(Protocol):\n  def __getitem__(self, index: int) -> Any: ...\n  def __len__(self) -> int: ...\n```\n\n---\n\n```python\ndef commute(fn: Callable[[S, T], R]) -> Callable[[T, S], R]\n```\n\nCommutes the operands of a binary function. Does not (yet) work for varargs or functions other than 2-arity\n\n---\n\n```python\ndef identity(x: T) -> T\n```\n\nThe identity function\n\n---\n\n```python\ndef bind(fn: Callable[[Any], R], arg: Any, position: int = 0) -> Callable[[Any], R]\n```\n\nGiven a `n`-arity function `fn`, bind `arg` to the `position`th argument of `fn` and return a new function which takes `n-1` args. The new function behaves as if the positional argument at `posititon` was removed from the argument order.\n\nThe argument count is 0 based\n\nIf `fn.__code__.co_argcount` is less or equal to `posititon` the function will raise a `ValueError`\n\n---\n\n```python\ndef full(fn: Callable[[Any], R], *args: Any) -> Callable[[], R]\n```\n\nLike functools.partial, except requires you to fill in **all** the arguments of `fn`. Returns a new function\nthat passes `*args` to `fn` but takes no arguments itself and returns the return value of `fn`\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A small collection of functions I find useful",
    "version": "0.16.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea94c2f3cbc2f02bf17f527925c672b70f42a268057931c1deb912b7d8743738",
                "md5": "6e57b9da2decfadfe1edd7cdb9c71ddf",
                "sha256": "f6f751490e65a57ce1142eaefe07746736bf3218dde0dc744495b09e84969756"
            },
            "downloads": -1,
            "filename": "pyfunctional_elunico-0.16.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6e57b9da2decfadfe1edd7cdb9c71ddf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6403,
            "upload_time": "2023-04-11T22:24:49",
            "upload_time_iso_8601": "2023-04-11T22:24:49.035282Z",
            "url": "https://files.pythonhosted.org/packages/ea/94/c2f3cbc2f02bf17f527925c672b70f42a268057931c1deb912b7d8743738/pyfunctional_elunico-0.16.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e57b76f63f4aee5f3e8c24ab9648165ebdeea95926301e0a4076ad9937637b1",
                "md5": "a20be574406e739a27d43fa7d25d4390",
                "sha256": "66dc73d5343541f178b5767ae5cbb28975e8fb694afca6dba4b54131e55c1814"
            },
            "downloads": -1,
            "filename": "pyfunctional-elunico-0.16.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a20be574406e739a27d43fa7d25d4390",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5120,
            "upload_time": "2023-04-11T22:24:50",
            "upload_time_iso_8601": "2023-04-11T22:24:50.818674Z",
            "url": "https://files.pythonhosted.org/packages/3e/57/b76f63f4aee5f3e8c24ab9648165ebdeea95926301e0a4076ad9937637b1/pyfunctional-elunico-0.16.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-11 22:24:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "elunico",
    "github_project": "pyfunctional",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyfunctional-elunico"
}
        
Elapsed time: 0.11402s