4 module Puppet::Parser::Functions
5 newfunction(:unique, :type => :rvalue, :doc => <<-DOC
7 This function will remove duplicates from strings and arrays.
10 String or array with duplicates removed
17 You can also use this with arrays:
19 unique(["a","a","b","b","c","c"])
20 This returns: ["a","b","c"]
25 if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0
26 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.'])
29 raise(Puppet::ParseError, "unique(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
33 unless value.is_a?(Array) || value.is_a?(String)
34 raise(Puppet::ParseError, 'unique(): Requires either array or string to work with')
39 string = value.is_a?(String) ? true : false
41 # We turn any string value into an array to be able to shuffle ...
42 result = string ? result.split('') : result
43 result = result.uniq # Remove duplicates ...
44 result = string ? result.join : result
50 # vim: set ts=2 sw=2 et :