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