continuedfractions.utils#

class continuedfractions.utils.NamedCallableProxy(callable_: Callable, /, *, name: str = None)[source]#

Class wrapper to have named callable proxies, which can also work as enum.Enum values.

Adapted from Stack Overflow solution by Ceppo93:

Attributes

name

static __new__(cls, callable_: Callable, /, *, name: str = None) NamedCallableProxy[source]#

Constructor

Parameters:
callable_callable

The callable to name and proxy.

namestr, default=None

The user-defined name of the callable to use in __repr__(). If None the Python-defined default will be used.

Returns:
callable

A named callable proxy.

Examples

>>> square = NamedCallableProxy(lambda x: x ** 2, name="square: x |--> x^2")
>>> square
NamedCallableProxy("square: x |--> x^2")
>>> list(map(square, [1, 2, 3, 4, 5]))
[1, 4, 9, 16, 25]