Puppet Function: array_union

Defined in:
lib/puppet/parser/functions/array_union.rb
Function type:
Ruby 3.x API

Overview

array_union()Array

Return the union of two Arrays.

Examples:


$arr_x = ['1','2']
$arr_y = ['2','3','4']

$res = array_union($arr_x, $arr_y)

$res contains:
  ['1','2','3','4']

Returns:

  • (Array)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/parser/functions/array_union.rb', line 2

newfunction(:array_union, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|

  unless args.length == 2
  Return the union of two `Arrays`.

  @example

    $arr_x = ['1','2']
    $arr_y = ['2','3','4']

    $res = array_union($arr_x, $arr_y)

    $res contains:
      ['1','2','3','4']

  @return [Array]
  ENDHEREDOC
    raise Puppet::ParseError, ("array_union(): wrong number of arguments (#{args.length}; must be 2)")
  end
  unless args[0].is_a?(Array) or args[0].is_a?(String)
    raise Puppet::ParseError, "array_union(): expects the first argument to be an array or string, got #{args[0].inspect} which is of type #{args[0].class}"
  end
  unless args[1].is_a?(Array) or args[0].is_a?(String)
    raise Puppet::ParseError, "array_union(): expects the second argument to be an array or string, got #{args[1].inspect} which is of type #{args[1].class}"
  end

  Array(args[0]) | Array(args[1])

end