from operator import or_


def _default_list_condition_func(col_attr, value, condition_func):
    """The default condition func for a list of data.

    Given the condition func for single item of data, this function
    wrap the condition_func and return another condition func using
    or_ to merge the conditions of each single item to deal with a
    list of data item.

    Args:
       col_attr: the colomn name
       value: the column value need to be compared.
       condition_func: the sqlalchemy condition object like ==

    Examples:
       col_attr is name, value is ['a', 'b', 'c'] and
       condition_func is ==, the returned condition is
       name == 'a' or name == 'b' or name == 'c'
    """
    conditions = []
    for sub_value in value:
        condition = condition_func(col_attr, sub_value)
        if condition is not None:
            conditions.append(condition)
    if conditions:
        return or_(*conditions)
    else:
        return None