Skip to content
Snippets Groups Projects
Commit 90c20998 authored by Valentin Lorentz's avatar Valentin Lorentz
Browse files

Comments.

parent 6a136034
No related branches found
No related tags found
No related merge requests found
......@@ -6,19 +6,25 @@ from ppp_datamodel.nodes.list_operators import *
__all__ = ['simplify']
def simplify_union(tree):
# Trivial cases
if len(tree.list) == 0:
return List([])
elif len(tree.list) == 1:
return tree.list[0]
# Partition the items in lists / non-lists
list_ = [x for x in tree.list if x]
lists = (x.list for x in list_ if isinstance(x, List))
not_lists = [x for x in list_ if not isinstance(x, List)]
# Make union of lists
lists = list(set(itertools.chain(*lists)))
if not_lists:
if not_lists: # If there are non-lists (eg. triples)
all_ = not_lists
all_.append(List(lists))
return Union(all_)
else:
else: # If there are only lists
return List(lists)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment