import functools


def mapreduce(map_func, reduce_func, gen, *args, **kwargs):
    """Return a map and reduce generator.

    Parameters
    ----------
    map_func : callable
        The map function.

    reduce_func : callable
        The reduce_function.

    gen : generator or iterator
        The inputs.

    *args, **kwargs
        Passed to the `functools.reduce` function.

    Returns
    -------
    generator
        The map-reduce generator.

    """
    return functools.reduce(reduce_func, map(map_func, gen), *args, **kwargs)