def foldl(function, xs, acc):
    """
    To simulate reduce functionality. Start from left and take 2 elements at a time.

    For example:

    foldl(f, [a, b, c], z) == f(f(f(z, a), b), c)
    """
    result = acc
    for elem in xs:
        result = function(result, elem)

    return result