@curry
def leaves_of_type(types, expr):
 if (not isinstance(expr, types)):
  return set([expr])
 else:
  return set.union(*map(leaves_of_type(types), expr._inputs))

@ curry def leaves_of_type ( types , expr ) : if ( not isinstance ( expr , types ) ) : return set ( [ expr ] ) else : return set . union ( * map ( leaves_of_type ( types ) , expr . _inputs ) )
leaves of an expression skipping all operations of type types .