title: Conditionally return element in Map() with Dart
body: <p>Let's say I have an iterable (be it a map (keys), list, set, etc), and wish use Map() to transform it into another iterable with function f. However I wish for f to only return a value if a condition is met, after transforming it.</p>
  
  <pre><code>List&lt;int&gt; a = [1,2,3,4,5,6];
  List&lt;int&gt; b = a.map((e) =&gt; (e % 2 == 0) ? e * 10 : null);
  
  assert(b == [20,40,60]);
  </code></pre>
  
  <p>However this returns an error, as does any similar equivalent in map with mapEntry, such as:</p>
  
  <pre><code>Map&lt;int, String&gt; a = {1:a, 2:b, 3:c, 4:d, 5:e, 6:f};
  Map&lt;int, String&gt; b = a.map((k,v) =&gt; (k % 2 == 0) ? MapEntry(k*10,v) : null);
  
  assert(b.keys.toList&lt;int&gt;() == [20,40,60]);
  </code></pre>
  
  <p>Of course, there are ways to go around this by sacrificing efficiency and conciseness by looping over it before or after mapping the values to filter out unneeded values. Such as:</p>
  
  <pre><code>List&lt;int&gt; b = a.where((e) =&gt; e%2).map((e) =&gt; e * 10);
  List&lt;int&gt; b = a.map((e) =&gt; e * 10).where((e) =&gt; e%2);
  </code></pre>
  
  <p>Or simply manually looping with for...in or forEach() and iterating over <code>a</code> while conditionally adding the changed result to <code>b</code>, but this would be lengthy codewise and would lack the optimizations map() would have for the specialized operation.</p>
  
  <p>Do let me know if this is at all possible - micro-optimizations accumulate for big gains imho :).</p>
  
  <p>Any help is much appreciated!</p>