No, takeWhile
is not the right tool for this job.
As you noticed, it is lazy. It is intended to create a new iterable, and it only does something if you actually use that iterable. Here, you are not interested in the result at all, so you just want the "while" part, and don't care about the "take". Alternative:
for (debit in debits) {
if (balance.debit(debit) < 0) break;
}
I even find it easier to read.