def aggregate(sequence, func, seed=None):
    """
    Applies accumulator function over a sequence.
    
    Args:
        sequence: iterable
            Sequence of items to go through.
        
        func: callable
            Accumulator function expecting two arguments (res, next).
        
        seed: any
            Initial aggregation value. If set to None, the first item is
            used.
    
    Returns:
        any
    """
    
    res = seed
    
    for i, item in enumerate(sequence):
        if i == 0 and seed is None:
            res = item
            continue
        res = func(res, item)
    
    return res