def task_combine(iterator, creator_func, combiner_func):
    """
    Combine elements of an iterator (partition) by key in a dictionary.
    :param iterator:
    :param creator_func: a function to apply to the value, in its key's first
                        occurrence.
    :param combiner_func: a function to combine second and later occurrences
    :return:
    """
    r = dict()
    for k, v in iterator:
        r[k] = combiner_func(r[k], v) if k in r else creator_func(v)
    return r