Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / concat.rb
1 #
2 # concat.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:concat, :type => :rvalue, :doc => <<-EOS
7 Appends the contents of multiple arrays into array 1.
8
9 *Example:*
10
11     concat(['1','2','3'],['4','5','6'],['7','8','9'])
12
13 Would result in:
14
15   ['1','2','3','4','5','6','7','8','9']
16     EOS
17   ) do |arguments|
18
19     # Check that more than 2 arguments have been given ...
20     raise(Puppet::ParseError, "concat(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2
21
22     a = arguments[0]
23
24     # Check that the first parameter is an array
25     unless a.is_a?(Array)
26       raise(Puppet::ParseError, 'concat(): Requires array to work with')
27     end
28
29     result = a
30     arguments.shift
31
32     arguments.each do |x|
33       result = result + (x.is_a?(Array) ? x : [x])
34     end
35
36     return result
37   end
38 end
39
40 # vim: set ts=2 sw=2 et :