from functools import reduce


def foldr(function, acc, xs):
    """Reduces a sequence with a function in a right-associative manner.


    It is helpful to visualize the right-fold as the following transformation.

         foldr f acc [1, 2, 3, 4, 5]

        +                           f
       / \                         / \ 
    [1]   +                       1   f
         / \                         / \ 
      [2]   +                       2   f
           / \                         / \ 
        [3]   +                       3   f
             / \                         / \ 
          [4]   +                       4   f
               / \                         / \ 
            [5]   []                      5   acc

    Parameters
    ----------
    function : def function(x: A, y: B) -> B
        The combining function.
    acc : B
        The accumulating value.
    xs : Sequence[A]
        The sequence to fold.

    Returns
    -------
    B
        The reduced value.

    Examples
    --------
    >>> result = foldr(lambda x, y: x-y, 0, [1, 2, 3, 4, 5])
    >>> result == (1 - (2 - (3 - (4 - (5 - 0)))))
    True
    """
    return reduce(lambda x, y: function(y, x), reversed(xs), acc)