title: How to filter a list of booleans and return the index for qualified items in Dart?
body: <p>I am using Seive method to calculate prime numbers up to a limit (say 100). </p>
  
  <p>I constructed a <code>List&lt;bool&gt;</code> to hold if an index (which will eventually be the number) is prime or not. This part is fine. </p>
  
  <p>Finally, I need return the numbers (index). Now I am using: </p>
  
  <pre><code>for(var i=2;i&lt;=max;i++) {
      if(!is_composite[i]){
        primes.add(i);
      }
  }
  return primes;
  </code></pre>
  
  <p>This will give the correct list containing only the prime numbers. </p>
  
  <p>I am wondering if I can do a filter on <code>is_composite</code> and returns the "index" associated?  </p>
  
  <p>As requested, the complete code:</p>
  
  <pre><code>List&lt;int&gt; findPrimes(int max) {
    var is_composite=List&lt;bool&gt;(max+1);
    var primes=List&lt;int&gt;();
  
    is_composite.fillRange(0, max, false);
    for(var i=4;i&lt;=max;i+=2) {
      is_composite[i]=true;
    }
  
    var next_prime=3;
    var stop=sqrt(max);
  
    while(next_prime&lt;=stop) {
      for(var i=next_prime*2;i&lt;=max;i+=next_prime) {
        is_composite[i]=true;
      }
      next_prime+=2;
      while(next_prime&lt;=max &amp;&amp; is_composite[next_prime]) {
        next_prime+=2;
      }
    }
  
    // TODO: is there a beter way instead of iterating the list?  
    for(var i=2;i&lt;=max;i++) {
      if(!is_composite[i]){
        primes.add(i);
      }
    }
    return primes;
  }
  </code></pre>