betty.functools module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.functools module

Provide functional programming utilities.

class betty.functools.Do

  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)
  async until(*conditions: Callable[[_DoFReturnT], None | bool | Awaitable[None | bool]], retries: int = 5, timeout: int = 300, interval: int | float = 0.1) → _DoFReturnT

    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.

class betty.functools.Uniquifier

  Bases: `Generic`[`_ValueT`]

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

  __init__(*values: Iterable[_ValueT], key: Callable[[_ValueT], Any] | None = None)

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

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

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

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