title: How do I update a list of maps with the values from another list of maps?
body: <p>I have list of maps like so:</p>
  <pre><code>primary_list = [
    %{&quot;id&quot; =&gt; &quot;cue&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; -15.0, &quot;z&quot; =&gt; 0.0},
    %{&quot;id&quot; =&gt; &quot;ball_1&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; 15.0, &quot;z&quot; =&gt; 0.0},
    %{&quot;id&quot; =&gt; &quot;ball_2&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; 17.0, &quot;z&quot; =&gt; 1.1},
    %{&quot;id&quot; =&gt; &quot;ball_3&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; 17.0, &quot;z&quot; =&gt; -1.1}
  ]
  </code></pre>
  <p>And another one, like so:</p>
  <pre><code>new_list = [
      %{&quot;ball_1&quot; =&gt; %{x: 14.684729230724962, y: 0.0, z: 0.0}, 
      &quot;cue&quot; =&gt; %{x: 16.68472923072496, y: 0.0, z: 0.0}}, 
      %{&quot;ball_2&quot; =&gt; %{x: 17.68472923072496, y: 0.0, z: 1.1}, 
      &quot;cue&quot; =&gt; %{x: 15.684729230724962, y: 0.0, z: 1.1}}, 
      %{&quot;ball_3&quot; =&gt; %{x: 17.68472923072496, y: 0.0, z: -1.1}, 
      &quot;cue&quot; =&gt; %{x: 15.684729230724962, y: 0.0, z: -1.1}}, 
      %{&quot;ball_2&quot; =&gt; %{x: 17.68472923072496, y: 0.0, z: 0.0}, 
      &quot;cue&quot; =&gt; %{x: 15.684729230724962, y: 0.0, z: 0.0}}, 
      %{&quot;ball_3&quot; =&gt; %{x: 17.68472923072496, y: 0.0, z: 0.0}, 
      &quot;cue&quot; =&gt; %{x: 15.684729230724962, y: 0.0, z: 0.0}}
  ]
  </code></pre>
  <p>How do I iterate over the second map, and apply the changes to the x, y, and z values to the first map based on the ID, while keeping the format of the first such that the final result would look something like this:</p>
  <pre><code>new_primary_list = [
      %{&quot;id&quot; =&gt; &quot;cue&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; 15.684729230724962, &quot;z&quot; =&gt; 0.0},
      %{&quot;id&quot; =&gt; &quot;ball_1&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; 14.684729230724962, &quot;z&quot; =&gt; 0.0},
      %{&quot;id&quot; =&gt; &quot;ball_2&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; 17.68472923072496, &quot;z&quot; =&gt; 0.0},
      %{&quot;id&quot; =&gt; &quot;ball_3&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; 17.68472923072496, &quot;z&quot; =&gt; 0.0}
  ]
  </code></pre>
  <p>Some items are repeated, but the final value should be the last update (such as in the case of <code>ball_2</code> and <code>ball_3</code>). I tried this:</p>
  <pre><code>new_result = Enum.map(result, fn  res -&gt;
      Enum.map(collision_map, fn cmap -&gt; 
          Enum.map(cmap, fn {k, v} -&gt;
              if res[&quot;id&quot;] == k do
                  res
                  |&gt; Map.put(&quot;x&quot;, v[&quot;x&quot;])
                  |&gt; Map.put(&quot;z&quot;, v[&quot;z&quot;])
              end
          end)
      end)
  end)
  </code></pre>
  <p>But all I ended up with was a mess of list of a list of a list with lots of <code>nil</code> values:</p>
  <pre><code>[
      [nil, nil],  [nil, nil], 
      [%{&quot;id&quot; =&gt; &quot;ball_3&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; nil, &quot;z&quot; =&gt; nil}, nil], 
      [nil, nil], 
      [%{&quot;id&quot; =&gt; &quot;ball_3&quot;, &quot;is_idle&quot; =&gt; true, &quot;velocity_x&quot; =&gt; 0.0, &quot;velocity_z&quot; =&gt; 0.0, &quot;x&quot; =&gt; nil, &quot;z&quot; =&gt; nil}, nil]
  ]
  </code></pre>
  <p>Is there anything else I can try?</p>