def REDUCE(_input, initial_value, _in):
    """
    Applies an expression to each element in an array and combines them into a single value.
    See https://docs.mongodb.com/manual/reference/operator/aggregation/reduce/
    for more details
    :param _input: Can be any valid expression that resolves to an array.
    :param initial_value: The initial cumulative value set before in is applied to the first element of the input array.
    :param _in: A valid expression that reduce applies to each element in the input array in left-to-right order.
    :return: Aggregation operator
    """
    return {'$reduce': {'input': _input, 'initialValue': initial_value, 'in': _in}}