from itertools import islice

def chunked(items, n):
    if n <= 0:
        raise ValueError("n must be greater than 0")
    
    it = iter(items)
    while True:
        chunk = list(islice(it, n))
        if not chunk:
            break
        yield chunk
