5 module Puppet::Parser::Functions
6 newfunction(:unique, :type => :rvalue, :doc => <<-EOS
7 This function will remove duplicates from strings and arrays.
17 You can also use this with arrays:
19 unique(["a","a","b","b","c","c"])
27 if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0
28 function_deprecation([:unique, 'This method is deprecated, please use the core puppet unique function. There is further documentation for the function in the release notes of Puppet 5.0.'])
31 raise(Puppet::ParseError, "unique(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
35 unless value.is_a?(Array) || value.is_a?(String)
36 raise(Puppet::ParseError, 'unique(): Requires either array or string to work with')
41 string = value.is_a?(String) ? true : false
43 # We turn any string value into an array to be able to shuffle ...
44 result = string ? result.split('') : result
45 result = result.uniq # Remove duplicates ...
46 result = string ? result.join : result
52 # vim: set ts=2 sw=2 et :