source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/zip.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 7 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 986 bytes
Line 
1#
2# zip.rb
3#
4
5module Puppet::Parser::Functions
6 newfunction(:zip, :type => :rvalue, :doc => <<-EOS
7Takes 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.
8
9*Example:*
10
11 zip(['1','2','3'],['4','5','6'])
12
13Would result in:
14
15 ["1", "4"], ["2", "5"], ["3", "6"]
16 EOS
17 ) do |arguments|
18
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
22
23 a = arguments[0]
24 b = arguments[1]
25
26 unless a.is_a?(Array) and b.is_a?(Array)
27 raise(Puppet::ParseError, 'zip(): Requires array to work with')
28 end
29
30 flatten = function_str2bool([arguments[2]]) if arguments[2]
31
32 result = a.zip(b)
33 result = flatten ? result.flatten : result
34
35 return result
36 end
37end
38
39# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.