5 module Puppet::Parser::Functions
6 newfunction(:zip, :type => :rvalue, :doc => <<-EOS
7 Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments.
11 zip(['1','2','3'],['4','5','6'])
15 ["1", "4"], ["2", "5"], ["3", "6"]
19 # Technically we support three arguments but only first is mandatory ...
20 raise(Puppet::ParseError, "zip(): Wrong number of arguments " +
21 "given (#{arguments.size} for 2)") if arguments.size < 2
26 unless a.is_a?(Array) and b.is_a?(Array)
27 raise(Puppet::ParseError, 'zip(): Requires array to work with')
30 flatten = arguments[2] if arguments[2]
35 # We can have either true or false, or string which resembles boolean ...
36 unless [FalseClass, TrueClass, String].include?(klass)
37 raise(Puppet::ParseError, 'zip(): Requires either ' +
38 'boolean or string to work with')
41 if flatten.is_a?(String)
42 # We consider all the yes, no, y, n and so on too ...
43 flatten = case flatten
45 # This is how undef looks like in Puppet ...
46 # We yield false in this case.
48 when /^$/, '' then false # Empty string will be false ...
49 when /^(1|t|y|true|yes)$/ then true
50 when /^(0|f|n|false|no)$/ then false
51 when /^(undef|undefined)$/ then false # This is not likely to happen ...
53 raise(Puppet::ParseError, 'zip(): Unknown type of boolean given')
59 result = flatten ? result.flatten : result
65 # vim: set ts=2 sw=2 et :