title: using .map (or another stdlib feature) to create a hash not array
body: <p>I'm trying to target JMS servers in the cloud, the puppet module init.pp needs to add a key to a hash.  </p>
  
  <p>I'm reading a block of hiera and having to extract parts of it to form a new hash.  .each doesn't return any values so I'm using .map.
  The values I'm getting out are exactly as I want, however when I tried a deep_merge I discovered that .map outputs as an array.</p>
  
  <p>service.yaml</p>
  
  <pre><code>jms_subdeployment_instances:
     'BPMJMSModuleUDDs:BPMJMSSubDM':
        ensure:     'present'
        target:
         - 'BPMJMSServer_auto_1'
         - "BPMJMSServer_auto_%{::ec2_tag_name}"
        targettype:
          - 'JMSServer'
          - 'JMSServer'      
  </code></pre>
  
  <p>init.pp</p>
  
  <pre><code>  $jms_subdeployments = lookup('jms_subdeployment_instances', $default_params)
    $jms_target_args = $jms_subdeployments.map |$subdep, $value| {
      $jms_short_name = $subdep[0, 3]
      $jms_subdeployment_inst = $array_domain_jmsserver_addresses.map |$index, $server| {
        "${jms_short_name}JMSServer_auto_${server}"
  
        if defined('$jms_subdeployment_inst') {
          $jmsTargetArg = {
            "${subdep}" =&gt; {
              'target' =&gt; $jms_subdeployment_inst
            }
          }
        }
      }
  
    $merge_subdeployment_targets = merge($jms_subdeployments, $jms_target_args)
  
  
  
  ```Output
  New JMS targets are : [{BPMJMSModuleUDDs:BPMJMSSubDM =&gt; {target =&gt; [BPMJMSServer_auto_server101, BPMJMSServer_auto_server102]}}]
  </code></pre>
  
  <p>The enclosing [ ] are causing me trouble.  As far as I can see, in puppet .to_h doesn't work either</p>
  
  <p>Thanks</p>
  
  <p>Update 22/07/2019:</p>
  
  <p>Thanks for the reply, I've had to tweak it slightly because puppet was failing with "Server Error: Evaluation Error: Error while evaluating a Method call, 'values' parameter 'hsh' expects a Hash value, got Tuple"</p>
  
  <pre><code>  $array_domain_jmsserver_addresses = 
    any2array(hiera('pdb_domain_msserver_addresses'))
    $array_domain_jmsserver_addresses.sort()
    $jms_subdeployments = lookup('jms_subdeployment_instances', $default_params)
    $hash_domain_jmsserver_addresses = Hash($array_domain_jmsserver_addresses)
  
    if $hash_domain_jmsserver_addresses.length &gt; 0 {
        $jms_target_arg_tuples = $jms_subdeployments.keys.map |$subdep| {
        $jms_short_name = $subdep[0, 3]
        $jms_subdeployment_inst = regsubst(
            $hash_domain_jmsserver_addresses.values, /^/, "${jms_short_name}JMSServer_auto_")
  
    # the (key, value) tuple to which this element maps
    [ $subdep, { 'target' =&gt; $jms_subdeployment_inst } ]
  }
  
  $jms_target_args = Hash($jms_target_arg_tuples)
  } else {
  $jms_target_args = {}
  }
  
  notify{"Normal array is : ${jms_subdeployments}": }
  notify{"Second array is : ${jms_target_args}": }  
  
  $merge_subdeployment_targets = deep_merge($jms_subdeployments, $jms_target_args)
  notify{"Merged array is : ${merge_subdeployment_targets}": }
  </code></pre>
  
  <blockquote>
    <p>Normal is : {BPMJMSModuleUDDs:BPMJMSSubDM => {ensure => present, target => [BPMJMSServer_auto_1, BPMJMSServer_auto_server1], targettype => [JMSServer, JMSServer]},</p>
    
    <p>Second is : {BPMJMSModuleUDDs:BPMJMSSubDM => {target => [BPMJMSServer_auto_server2]}</p>
    
    <p>Merged is : {BPMJMSModuleUDDs:BPMJMSSubDM => {ensure => present, target => [BPMJMSServer_auto_server2], targettype => [JMSServer, JMSServer]}</p>
  </blockquote>
  
  <p>Desired output it:</p>
  
  <blockquote>
    <p>{BPMJMSModuleUDDs:BPMJMSSubDM => {ensure => present, target => [BPMJMSServer_auto_1, BPMJMSServer_auto_server1, BPMJMSServer_auto_server2], targettype => [JMSServer, JMSServer, JMSServer]}</p>
  </blockquote>