gfw.common.iterables
Module that contains simple iterable utilities.
Functions
-
chunked_it(iterable, n)[source]
Splits an iterable into iterator chunks of length n. The last chunk may be shorter.
- Return type:
Iterator[chain[Any]]
-
binary_search_first_ge(items, start_value, key)[source]
Find index of first item in sorted list whose key >= start_value.
This function performs a binary search to efficiently locate the leftmost index
where the key of the item is greater than or equal to start_value.
- Parameters:
items (List[Any]) – Sorted list of items.
start_value (Any) – The value to compare to.
key (Callable[[Any], Any]) – Function to extract a comparable key from each item.
- Returns:
Index of the first item with key >= start_value, or -1 if no such item exists.
- Return type:
int