def reduce(reducer, data, chunk_size=DEFAULT_CHUNK_SIZE):
if not chunk_size:<EOL><INDENT>return finalize(reducer, fold(reducer, data))<EOL><DEDENT>chunks = generate_chunks(data, chunk_size)<EOL>intermediate = fold(reducer, next(chunks))<EOL>for chunk in chunks:<EOL><INDENT>intermediate = merge(reducer, intermediate, fold(reducer, chunk))<EOL><DEDENT>return finalize(reducer, intermediate)<EOL>
Repeatedly call fold and merge on data and then finalize.

    Arguments:
        data: Input for the fold function.
        reducer: The IReducer to use.
        chunk_size: How many items should be passed to fold at a time?

    Returns:
        Return value of finalize.