def concatenate(elems, operator='OR', class_to_embed_elem=None):
    """
    Receives a list of elements to be concatenated, to generate a type
    MatchFirst from pyParsing. Order is important given that it matches with the
    one found first

    :param elems: list of elements to concatenate
    :param operator: type of operator to concatenate with
    :param class_to_embed_elem: class to use to initialize each element in the list
    :return: MatchFirst object representing the optional matching with any of the elements in the list
    """
    combined_elems = class_to_embed_elem(elems[0]) if class_to_embed_elem else elems[0]

    for e in elems[1:]:
        elem_to_concat = class_to_embed_elem(e) if class_to_embed_elem else e

        if operator == 'OR':
            combined_elems = combined_elems | elem_to_concat

        elif operator == 'AND':
            combined_elems = combined_elems & elem_to_concat

        elif operator == 'LONGEST_OR':  # OR that matches the longest expression
            combined_elems = combined_elems ^ elem_to_concat

    return combined_elems