def aiter()

in elasticsearch_serverless/_async/helpers.py [0:0]


def aiter(x: Union[Iterable[T], AsyncIterable[T]]) -> AsyncIterator[T]:
    """Turns an async iterable or iterable into an async iterator"""
    if hasattr(x, "__anext__"):
        return x  # type: ignore[return-value]
    elif hasattr(x, "__aiter__"):
        return x.__aiter__()

    async def f() -> AsyncIterable[T]:
        nonlocal x
        ix: Iterable[T] = x
        for item in ix:
            yield item

    return f().__aiter__()