aioplus.aislice

aioplus.aislice(aiterable, start, stop=None, step=None, /)

Return selected elements from the iterable.

Parameters:
  • aiterable (AsyncIterable of T) – An asynchronous iterable of objects to slice.

  • start (int) – The index of the first object to include. If stop is None, treated as the end index, and slicing starts from 0.

  • stop (int, optional) – The index at which to stop (exclusive). If not provided, start is interpreted as stop, and slicing starts from 0.

  • step (int, optional) – The difference between consecutive values. Defaults to 1.

Returns:

An asynchronous iterable yielding selected objects according to the slice parameters.

Return type:

AsyncIterable of T

Examples

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