4 module Puppet::Parser::Functions
5 newfunction(:difference, :type => :rvalue, :doc => <<-DOC
7 This function returns the difference between two arrays.
9 The returned array is a copy of the original array, removing any items that
10 also appear in the second array.
12 @example Example usage
14 difference(["a","b","c"],["b","c","d"])
18 Since Puppet 4 the minus (-) operator in the Puppet language does the same thing:
19 ['a', 'b', 'c'] - ['b', 'c', 'd']
23 The difference between the two given arrays
28 # Two arguments are required
29 raise(Puppet::ParseError, "difference(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2
34 unless first.is_a?(Array) && second.is_a?(Array)
35 raise(Puppet::ParseError, 'difference(): Requires 2 arrays')
38 result = first - second
44 # vim: set ts=2 sw=2 et :