import itertools


def make_batcher(batch_size, strict_batching=True):
    """
    Convert a single-item generator into a generator of batched items

    Args:
        batch_size (int): number of items to batch together per iteration
        strict_batching (bool): If True, will not yield batches that are smaller
            than batch_size.  This can happen at the end of a generator when
            there are not enough items left.

    Returns:
        A function which takes as input a generator and outputs a new generator
    """

    def inner(single_item_generator):
        while True:
            batch = list(itertools.islice(single_item_generator, 0, batch_size))
            if len(batch) == 0 or (strict_batching and len(batch) < batch_size):
                break
            yield batch

    return inner