A small collection of functions I find useful
Project description
pyfunctional
Find it on PyPI
This is a collection of functional tools I like to use in Python
Contents
alleq(iterable: Iterable[S]) -> bool
returns True if an iterable is empty or if all elements are equal to the first
transpose(double_iterable: Iterable[Iterable[S]])
an iterable object that takes a nested iterable and transposes it lazily
repeat(element: E, count: int)
an iterable object that takes an element and a count and returns that element count
times
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.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyfunctional-elunico-0.9.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 930280caa5099b0bec5f2ad6613d7dcf189d92a086898dd55f1ded4b4463b18a |
|
MD5 | b2fdb3dc7e5b503c1187eb86fec25eaa |
|
BLAKE2b-256 | 2307648c6886bc14a778b943423b80842c8dbaee8c54f83d6440a9fbfa0a37d4 |
Hashes for pyfunctional_elunico-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da6a5f3f367adcdcd52221c98b7e4f0304feb028f62b22479846c6e04c46ec8 |
|
MD5 | ffb7494f14e7d0cab8db4ee136ba300a |
|
BLAKE2b-256 | d9f7dda96adcb29286d9068bad57550e109ebac0eb632e5bfc7dad485d8e5a91 |