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