aioplus.aminmax¶
- async aioplus.aminmax(aiterable, /, *, key=None, default=<enum 'Sentinel'>)¶
Return the smallest and the largest items in
aiterable.- Parameters:
aiterable (AsyncIterable[T]) – An asynchronous iterable of objects.
key (Callable[[T], SupportsRichComparison], optional) – A function that extracts a comparison key from each element in the iterable.
default (tuple[D1, D2], optional) – The default values to return if the iterable is empty.
- Returns:
The smallest and the largest item in the iterable or the default values.
- Return type:
tuple[T | D1, T | D2]
Examples
>>> import asyncio >>> >>> from aioplus import aminmax, arange >>> >>> async def main() -> None: >>> '''Run the program.''' >>> aiterable = arange(23) >>> smallest, largest = await aminmax(aiterable) >>> print(f'min(aiterable) == {smallest}') >>> print(f'max(aiterable) == {largest}') >>> >>> if __name__ == '__main__': >>> asyncio.run(main())
Notes
This function is not comparison-optimized.