O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Creating the iterator

We now have a function in our Fridge to return an iterator, but we still need to write this iterator. To keep things simple in this exercise, we will simply rely on the iterator of the Fridge's list.

Now, we will create this StorableIterator class:

package fridgeManager;
class StorableIterator
{
private var iterator : Iterator<Storable>;
public function hasNext() : Bool
{
return iterator.hasNext();
}
public function next() : Storable
{
return iterator.next();
}
public function new(fridge : Fridge)
{
iterator = fridge.storedItems.iterator();
}
}

What just happened?

As you can see it is pretty simple and relies on the fridge list's iterator.

Just remember that the hasNext function returns a Bool stating whether ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required