aioplus.anth

async aioplus.anth(aiterable, /, *, n, default=<enum 'Sentinel'>)

Return the nth item or a default value.

Parameters:
  • aiterable (AsyncIterable[T]) – An asynchronous iterable to retrieve the nth item from.

  • n (SupportsIndex) – The index of the item to retrieve, starting from 0.

  • default (D, optional) – A default value to return if the nth item does not exist. If not provided, IndexError will be raised if the nth item is not found.

Returns:

The nth item or the default value.

Return type:

T or D

Examples

>>> import asyncio
>>>
>>> from aioplus import anth, arange
>>>
>>> async def main() -> None:
>>>     '''Run the program.'''
>>>     aiterable = arange(23)
>>>     value = await anth(aiterable, n=4)
>>>     print(f'value = {value}')
>>>
>>> if __name__ == '__main__':
>>>     asyncio.run(main())