import itertools


def compact_batches(batches):
    """Pack down batches to lists of continuous batches."""

    return [
        [x[1] for x in g]
        for k, g in itertools.groupby(enumerate(batches), lambda i_x: i_x[0] - i_x[1])
    ]