Domanda

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?

È stato utile?

Soluzione

The Gee iterators/Traversables implement foreach as a method:

list.filter (s => s > "a").foreach (s => { stdout.printf (@"s\n"); return true; });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top