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 raise(Puppet::ParseError, "unique(): Wrong number of arguments " +
28 "given (#{arguments.size} for 1)") if arguments.size < 1
32 unless value.is_a?(Array) || value.is_a?(String)
33 raise(Puppet::ParseError, 'unique(): Requires either ' +
34 '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 :