title: Iterable lazy functions getting too lazy
body: <p>This code trips me up. In this code the <em>takeWhile</em> makes sense - take up debits, reducing the balance while the balance is positive. The problem is with this code nothing happens. No calls to <em>balance.debit()</em> are made and I guess the reason is <em>takeWhile filtering happens lazily</em>. </p>
  
  <p>I can ensure that it gets called by tacking on a <em>toList()</em> call, but that seems wasteful as a list is not really needed. </p>
  
  <ul>
  <li>What is a better way to do this?</li>
  <li>Is <em>takeWhile</em> not the right tool for this job?</li>
  </ul>
  
  <p>Code follows:
  </p>
  
  <pre class="lang-dart prettyprint-override"><code>class Balance {
    Balance(this._balance);
    double _balance;
    debit(double amount) {
      print('Debiting $amount');
      return (_balance -= amount);
    }
  }
  
  main() {
    final balance = new Balance(3.0);
    final debits = [ 1.0, 2.0, 3.0 ];
    debits.takeWhile((debit) =&gt; balance.debit(debit) &gt; 0);
  
    //////////////////////
    //debits
    //  .takeWhile((debit) =&gt; balance.debit(debit) &gt; 0)
    //  .toList();
  }
  </code></pre>