Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / union.rb
1 #
2 # union.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:union, :type => :rvalue, :doc => <<-EOS
7 This function returns a union of two or more arrays.
8
9 *Examples:*
10
11     union(["a","b","c"],["b","c","d"])
12
13 Would return: ["a","b","c","d"]
14     EOS
15   ) do |arguments|
16
17     # Check that 2 or more arguments have been given ...
18     raise(Puppet::ParseError, "union(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2
19
20     arguments.each do |argument|
21       raise(Puppet::ParseError, 'union(): Every parameter must be an array') unless argument.is_a?(Array)
22     end
23
24     arguments.reduce(:|)
25   end
26 end
27
28 # vim: set ts=2 sw=2 et :