Sha256: 5ae2d738e380c8520c24594315ecf1780de9db127b34572340d235a8d8ed6d15
Contents?: true
Size: 1.39 KB
Versions: 21
Compression:
Stored size: 1.39 KB
Contents
Puppet::Parser::Functions::newfunction( :map, :type => :rvalue, :arity => -3, :doc => <<-DOC Applies a parameterized block to each element in a sequence of entries from the first argument and returns an array with the result of each invocation of the parameterized block. This function takes two mandatory arguments: the first should be an Array, Hash, or of Enumerable type (integer, Integer range, or String), and the second a parameterized block as produced by the puppet syntax: $a.map |$x| { ... } map($a) |$x| { ... } When the first argument `$a` is an Array or of enumerable type, the block is called with each entry in turn. When the first argument is a hash the entry is an array with `[key, value]`. Example Using map with two arguments # Turns hash into array of values $a.map |$x|{ $x[1] } # Turns hash into array of keys $a.map |$x| { $x[0] } When using a block with 2 parameters, the element's index (starting from 0) for an array, and the key for a hash is given to the block's first parameter, and the value is given to the block's second parameter.args. Example Using map with two arguments # Turns hash into array of values $a.map |$key,$val|{ $val } # Turns hash into array of keys $a.map |$key,$val|{ $key } - Since 4.0.0 DOC ) do |args| function_fail(["map() is only available when parser/evaluator future is in effect"]) end
Version data entries
21 entries across 21 versions & 1 rubygems