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.
- __init__(do: ~typing.Callable[[~_DoFP], ~betty.functools._DoFReturnT | ~typing.Awaitable[~betty.functools._DoFReturnT]], *do_args: ~typing.~_DoFP, **do_kwargs: ~typing.~_DoFP)[source]¶
- async until(*conditions: Callable[[_DoFReturnT], None | bool | Awaitable[None | bool]], retries: int = 5, timeout: int = 300, interval: int | float = 0.1) _DoFReturnT [source]¶
Perform the ‘do’ until it succeeds or as long as the given arguments allow.
- Parameters:
timeout – The timeout in seconds.
interval – The interval between ‘loops’ in seconds.
- betty.functools.filter_suppress(raising_filter: Callable[[_T], Any], exception_type: type[BaseException], items: Iterable[_T]) Iterator[_T] [source]¶
Filter values, skipping those for which the application of raising_filter raises errors.
- betty.functools.unique(*values: Iterable[_ValueT], key: Callable[[_ValueT], Any] | None = None) Iterator[_ValueT] [source]¶
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 thanset
.