4 module Puppet::Parser::Functions
5 newfunction(:delete_values, :type => :rvalue, :doc => <<-DOC
7 Deletes all instances of a given value from a hash.
11 delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')
12 Would return: {'a'=>'A','c'=>'C','B'=>'D'}
15 Since Puppet 4.0.0 the equivalent can be performed with the
16 built-in [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function:
17 $array.filter |$val| { $val != 'B' }
18 $hash.filter |$key, $val| { $val != 'B' }
20 @return [Hash] The given hash now missing all instances of the targeted value
24 raise(Puppet::ParseError, "delete_values(): Wrong number of arguments given (#{arguments.size} of 2)") if arguments.size != 2
26 hash, item = arguments
28 unless hash.is_a?(Hash)
29 raise(TypeError, "delete_values(): First argument must be a Hash. Given an argument of class #{hash.class}.")
31 hash.dup.delete_if { |_key, val| item == val }