Hack interface overview
There are a number of predefined interfaces in Hack. This post is going to give you an overview about the interfaces that are a subtype of Traversable.
Traversable<Tv>
This is an abstract interface. Each an every class that implements this interface may be use with foreach()
KeyedTraversable<Tk, Tv>
This is an abstract interface. When implementing this you may use your object with a foreach with keyes. Like foreach($c as $k => $v)
IteratorAggregate<Tv>
This interface requires you to have a getIterator() function that will return an external iterator.
Iterable<Tv>
Interface to create an iterable object that will work with foreach()
KeyedIterable<Tk, Tv>
Interface to create an iterable object that will work with foreach() with keyes. Like foreach($c as $k => $v).
Indexish<Tk, Tv>
Allows you to use the bracket syntax.
Iterator<Tv>
Interface for external iterators or objects that can be iterated themselves internally.
KeyedIterator<Tk, Tv>
Same as Iterator but with keys.
Continuation<Tv>
This object is return from generators. The manual has an excellent example of how to use Continuation.
Leave a Comment