1
using Gee;

int main (string[] args) {
        ArrayList<string> list = new ArrayList<string>();

        list.add ("a");
        list.add ("b");
        list.add ("c");

        foreach (var s in list.filter (s => s > "a")) stdout.printf (@"s\n");

        return 0;
}

This doesn't compile, because Traversable<G>.filter doesn't return an object with an "iterate()" method, but an Iterator<G>.

Is there any way to get foreach working on an iterator?

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113

1 Answers1

2

The Gee iterators/Traversables implement foreach as a method:

list.filter (s => s > "a").foreach (s => { stdout.printf (@"s\n"); return true; });
apmasell
  • 7,033
  • 19
  • 28