Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a unique_list function #185

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
};
};
to_list;
};