>>> from Redy.Collections import Traversal, Flow
    >>> x = [1, 1, 2]
    >>> assert Flow(x)[Traversal.chunk][list].unbox == [[1, 1], [2]]
    >>> assert Flow([])[Traversal.chunk][list].unbox == []

def chunk(seq: ActualIterable[T]) -> ActualIterable[ActualIterable[T]]:
    """
    >>> from Redy.Collections import Traversal, Flow
    >>> x = [1, 1, 2]
    >>> assert Flow(x)[Traversal.chunk][list].unbox == [[1, 1], [2]]
    >>> assert Flow([])[Traversal.chunk][list].unbox == []
    """
    seq = iter(seq)
    try:
        head = next(seq)
    except StopIteration:
        return iter(seq)

    current_status = head
    group = [head]
    for each in seq:
        status = each
        if status != current_status:
            yield group
            group = [each]
        else:
            group.append(each)
        current_status = status
    if group:
        yield group