code: def flatten_tree(test, enumerator, exp):
    
    return sum((flatten_tree(test, enumerator, subx) for subx in enumerator(exp)), []) if test(exp) else [exp]
docs: test is function(exp) >> bool.
    mapper is function(expression) >> list of subexpressions.
    returns [subexpression, ...].