union()
Return a list that is the union of individual lists.
Syntax
Parameter
Parameter | Definition |
---|---|
listn | PSL list containing elements that shall be united and returned in a single well-defined list Only the first two input lists, list1 and list2, are required; all others are optional. |
Description
The union() function returns a PSL list that contains the elements from all listn merged together. Unlike the difference() and intersection() functions, the list returned by the union function is a well-defined set without any duplicates.
The union( x, y ) function is similar to specifying the unique( x, y ) function using the string concatenation operator "." to perform union() and the unique() function to remove duplicates. The advantage in using the union() function over the unique() function occurs when x has no terminating new-line character, in which case the use of the "." operator could cause the last element of x and the first element of y to become treated as a single set element. The union() function adds a new line to the end of every nonempty list that is missing one.
If the return value is not the NULL list, the returned set is always terminated by a new line so that all set elements end with a new-line character.
Example
The following is an example of the union() function:
local group1,group2,group3,group4;
group1 = [1,2,3];
group2 = [3,4,5];
group3 = [5,6,7];
group4 = [7,8,9,10];
printf("%s\n",union(group1,group2,group3,group4));
# or you can do it this way:
printf("%s\n",union(group1,union(group2,union(group3,group4))));
return;
}
Each of the two printf() function statements prints a PSL list containing the integers 1 through 10.