source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/flatten.rb@ 30960

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

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 664 bytes
Line 
1#
2# flatten.rb
3#
4
5module Puppet::Parser::Functions
6 newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
7This function flattens any deeply nested arrays and returns a single flat array
8as a result.
9
10*Examples:*
11
12 flatten(['a', ['b', ['c']]])
13
14Would return: ['a','b','c']
15 EOS
16 ) do |arguments|
17
18 raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
19 "given (#{arguments.size} for 1)") if arguments.size != 1
20
21 array = arguments[0]
22
23 unless array.is_a?(Array)
24 raise(Puppet::ParseError, 'flatten(): Requires array to work with')
25 end
26
27 result = array.flatten
28
29 return result
30 end
31end
32
33# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.