Skip to content

Commit

Permalink
Add a unique_list function
Browse files Browse the repository at this point in the history
The unique_list function takes a list as parameter, and returns
a list without any duplicated elements. The order of the elements
is maintained (i.e. if the first occurrence of an element appears in
the list before the first occurrence of another, the former will
precede the latter in the final list).
  • Loading branch information
XaF committed Aug 7, 2018
1 parent 2ff00f7 commit 094de29
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pan/functions.pan
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,21 @@ function full_hostname_from_object = {
return (OBJECT);
};


@documentation{
desc = Function to deduplicate the content of a list, only the first \
occurence of each element in the list will be kept in the final \
list returned to the caller
}
function unique_list = {
to_dict = dict();
to_list = list();
foreach(idx; item; ARGV[0]) {
itemid = to_string(item);
if (!exists(to_dict[escape(itemid)])) {
append(to_list, item);
to_dict[escape(itemid)] = 1;
};
};
return(to_list);
};

0 comments on commit 094de29

Please sign in to comment.