aioplus.atail

aioplus.atail(aiterable, /, *, n)

Return the last n items of the aiterable.

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

  • n (SupportsIndex) – The number of items to retrieve from the end.

Returns:

An asynchronous iterable yielding the last n items of the aiterable.

Return type:

AsyncIterable[T]

Examples

>>> import asyncio
>>>
>>> from aioplus import arange, atail
>>>
>>> async def main() -> None:
>>>     '''Run the program.'''
>>>     async for num in atail(arange(23), n=4):
>>>         print(num)
>>>
>>> if __name__ == '__main__':
>>>     asyncio.run(main())

Notes

  • The last n items are buffered in memory before yielding;

  • Yields control to the event loop before producing each value.