title: How to add to an existing value in a map in Cypher?
body: <p>I want to replace the value of the 'Amount' key in a map (literal) with the sum of the existing 'Amount' value plus the new 'Amount' value such where both the 'type' and 'Price' match.  The structure I have so far is:</p>
  
  <pre><code>WITH [{type:1, Orders:[{Price:10,Amount:100},{Price:11,Amount:200},{Price:12,Amount:300}]},
  {type:2, Orders:[{Price:10,Amount:100},{Price:11,Amount:200},{Price:12,Amount:300}]},
  {type:3, Orders:[{Price:10,Amount:100},{Price:11,Amount:200},{Price:12,Amount:300}]}] as ExistingOrders,
  {type:2, Order:{Price:11,Amount:50}} as NewOrder
  </code></pre>
  
  <p><em>(I'm trying to get it to:)</em></p>
  
  <p>RETURN [{type:1, Orders:[{Price:10,Amount:100},{Price:11,Amount:200},{Price:12,Amount:300}]},
          {type:2, Orders:[{Price:10,Amount:100},{Price:11,Amount:<strong>250</strong>},{Price:12,Amount:300}]},
          {type:3, Orders:[{Price:10,Amount:100},{Price:11,Amount:200},{Price:12,Amount:300}]}] as <strong>CombinedOrders</strong></p>
  
  <p>If there is no existing NewOrder.type and NewOrder.Price then it should obviously insert the new record rather than add it together.</p>
  
  <p>Sorry, this is possibly really straight forward, but I'm not very good at this yet.</p>
  
  <p>thanks</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I should add, that I have been able to get this working for a simpler map structure as such:</p>
  
  <pre><code>WITH [{type:1, Amount:100},{type:2, Amount:200},{type:3, Amount:300}] as ExistingOrders,
  {type:2, Amount:50} as NewValue
  RETURN reduce(map=filter(p in ExistingOrders where not p.type=NewValue.type),x in [(filter(p2 in ExistingOrders where p2.type=NewValue.type)[0])]|CASE x WHEN null THEN NewValue ELSE {type:x.type,Amount:x.Amount+NewValue.Amount} END+map) as CombinedOrders
  </code></pre>
  
  <p>But I'm struggling I think because of the Orders[array] in my first example.</p>