betty.functools module

Provide functional programming utilities.

class betty.functools.Do[source]

Bases: Generic[_DoFP, _DoFReturnT]

A functional implementation of do-while functionality, with retries and timeouts.

Parameters:
__init__(do: typing.Callable[[~_DoFP], betty.functools._DoFReturnT | typing.Awaitable[betty.functools._DoFReturnT]], *do_args: typing.~_DoFP, **do_kwargs: typing.~_DoFP)[source]
Parameters:
async until(*conditions: Callable[[betty.functools._DoFReturnT], None | bool | Awaitable[None | bool]], retries: int = 5, timeout: int = 300, interval: int | float = 0.1) betty.functools._DoFReturnT[source]

Perform the ‘do’ until it succeeds or as long as the given arguments allow.

Parameters:
Return type:

typing.TypeVar(_DoFReturnT)

class betty.functools.Uniquifier[source]

Bases: Generic[T]

Yield the first occurrences of values in a sequence.

For the purpose of filtering duplicate values from an iterable, this works similar to set, except that this class supports non-hashable values. It is therefore slightly slower than set.

Parameters:

values (typing.Iterable[typing.TypeVar(T)])

__init__(*values: Iterable[betty.functools.T])[source]
Parameters:

values (typing.Iterable[typing.TypeVar(T)])

betty.functools.filter_suppress(raising_filter: Callable[[betty.functools.T], Any], exception_type: type[BaseException], items: Iterable[betty.functools.T]) Iterator[betty.functools.T][source]

Filter values, skipping those for which the application of raising_filter raises errors.

Parameters:
Return type:

typing.Iterator[typing.TypeVar(T)]

betty.functools.slice_to_range(indices: slice, iterable: Sized) Iterable[int][source]

Apply a slice to an iterable, and return the corresponding range.

Parameters:
Return type:

typing.Iterable[int]

betty.functools.walk(item: Any, attribute_name: str) Iterable[Any][source]

Walk over a graph of objects by following a single attribute.

Parameters:
Return type:

typing.Iterable[typing.Any]