Produce an iterable of interables of a maximum length from a (presumably
    longer) iterable. This is useful when only so many elements can be
    processed at once, such as an API that limits to n things per request.

    :param iterable: The iterable to chunk into iterables of size up to n.
    :param n: The maximum length of each iterable.
    :return: An iterable of iterables. Each iterable will be of size n, except
             possibly the last one which will contain fewer elements.

def chunk(iterable: Iterable[A], n: int) \
        -> Iterable[more_itertools.more.peekable]:
    """
    Produce an iterable of interables of a maximum length from a (presumably
    longer) iterable. This is useful when only so many elements can be
    processed at once, such as an API that limits to n things per request.

    :param iterable: The iterable to chunk into iterables of size up to n.
    :param n: The maximum length of each iterable.
    :return: An iterable of iterables. Each iterable will be of size n, except
             possibly the last one which will contain fewer elements.
    """
    iterator = iter(iterable)
    while True:
        chunk_ = more_itertools.peekable(itertools.islice(iterator, n))
        try:
            chunk_.peek()
        except StopIteration:
            return
        yield chunk_