from typing import List


def selection_rule_fn(l1: int, l2: int, lmax=None, lfilter=None) -> List[int]:
    """
    selection rule according to the triangle inequality:
    \|l1 - l2\| <= l  <= l1 + l2.

    This inequality is euqivalent to the following inequality system:
    (1) l1 + l2 >= l
    (2) l2 + l >= l1
    (3) l + l1 >= l2

    l1 and l2 can be the input orders and l is the output order
    or alternatively l1 and l2 can be the output order and one input order and l is the second input order.

    If lmax is given, then also: l <= lmax
    If lfilter is given, then also: lfilter(l) has to be True

    Note that as

    :return: list of l for which the conditions of the triangle inequality, lmax and lfilter hold
    """
    if lmax is None:
        l_max = l1 + l2
    else:
        l_max = min(lmax, l1 + l2)
    ls = list(range(abs(l1 - l2), l_max + 1))
    if lfilter is not None:
        ls = list(filter(lfilter, ls))
    return ls