title: Transform values of a Map in groovy
body: <p>Lets say I have a map <code>Map&lt;String, List&lt;Integer&gt;&gt;</code>. </p>
  
  <p>I want to transform this map into <code>Map&lt;String, Map&lt;Integer, Object&gt;&gt;</code> by applying <code>convert()</code> method for each pair of key and element of nested list.</p>
  
  <pre><code>Object convert(String key, Integer value)
  </code></pre>
  
  <p>How can I achieve that? </p>
  
  <p>I tried something like this:</p>
  
  <pre><code>map.collect { key, list -&gt;
      key: list.collectEntries {
          [(element): convert(key, element)]
      }
  }
  </code></pre>
  
  <p>but I'm getting  <code>ClassCastException: ArrayList cannot be cast to Map</code>.</p>