Sha256: ab871920353073a9afda7803f3a7d8baf16ba5fc1fba55f5aac02097f65a017d

Contents?: true

Size: 1.51 KB

Versions: 50

Compression:

Stored size: 1.51 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 3.4 for Array and Hash
- since 3.5 for other enumerables, and support for blocks with 2 parameters
- note requires `parser = future`
DOC
) do |args|
  function_fail(["map() is only available when parser/evaluator future is in effect"])
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb
puppet-3.8.7 lib/puppet/parser/functions/map.rb
puppet-3.8.7-x86-mingw32 lib/puppet/parser/functions/map.rb
puppet-3.8.7-x64-mingw32 lib/puppet/parser/functions/map.rb
puppet-3.8.6 lib/puppet/parser/functions/map.rb
puppet-3.8.6-x86-mingw32 lib/puppet/parser/functions/map.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb
puppet-3.8.6-x64-mingw32 lib/puppet/parser/functions/map.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb
puppet-3.8.5 lib/puppet/parser/functions/map.rb
puppet-3.8.5-x86-mingw32 lib/puppet/parser/functions/map.rb
puppet-3.8.5-x64-mingw32 lib/puppet/parser/functions/map.rb
puppet-3.8.4 lib/puppet/parser/functions/map.rb
puppet-3.8.4-x86-mingw32 lib/puppet/parser/functions/map.rb
puppet-3.8.4-x64-mingw32 lib/puppet/parser/functions/map.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/map.rb