pyfunctional
Find it on PyPI
This is a collection of functional tools I like to use in Python
Contents
def alleq(iterable: Iterable[S]) -> bool
returns True if an iterable is empty or if all elements are equal to the first
def transpose(double_iterable: Iterable[Iterable[S]])
an iterable object that takes a nested iterable and transposes it lazily
def repeat(element: E, count: int)
an iterable object that takes an element and a count and returns that element count times
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.
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
from typing import Protocol
class Indexable(Protocol):
def __getitem__(self, index: int) -> Any: ...
def __len__(self) -> int: ...
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
def identity(x: T) -> T
The identity function
def bind(fn: Callable[[Any], R], arg: Any, position: int = 0) -> Callable[[Any], R]
Given a n-arity function fn, bind arg to the positionth 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
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
Metadata
Release files for pyfunctional-elunico 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyfunctional-elunico-0.16.0.tar.gz | 5.1 kB | Without provenance | Details for pyfunctional-elunico-0.16.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfunctional_elunico-0.16.0-py3-none-any.whl | Python 3 | none | any | Details for pyfunctional_elunico-0.16.0-py3-none-any.whl |
Total release size: 11.5 kB
Release files / pyfunctional-elunico-0.16.0.tar.gz
| Download URL | pyfunctional-elunico-0.16.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66dc73d5343541f178b5767ae5cbb28975e8fb694afca6dba4b54131e55c1814
|
|
BLAKE2b-256 checksum How to use checksums |
3e57b76f63f4aee5f3e8c24ab9648165ebdeea95926301e0a4076ad9937637b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / pyfunctional_elunico-0.16.0-py3-none-any.whl
| Download URL | pyfunctional_elunico-0.16.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6f751490e65a57ce1142eaefe07746736bf3218dde0dc744495b09e84969756
|
|
BLAKE2b-256 checksum How to use checksums |
ea94c2f3cbc2f02bf17f527925c672b70f42a268057931c1deb912b7d8743738
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for pyfunctional-elunico 0.16.0
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.