Skip to main content

A small collection of functions I find useful

Project description

pyfunctional

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfunctional-elunico-0.8.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

pyfunctional_elunico-0.8.1-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page