Hack interface overview


HackInterfacesThere 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.


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)


This interface requires you to have a getIterator() function that will return an external iterator.


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.


Interface for external iterators or objects that can be iterated themselves internally.

KeyedIterator<Tk, Tv>

Same as Iterator but with keys.


This object is return from generators. The manual has an excellent example of how to use Continuation.


  1. Haha, Indexish, really? Would have been useful to see the interfaces’ definitions along with the name.

    • The implementation of Indexish looks like this:

      interface Indexish<Tk, Tv> extends KeyedContainer<Tk, Tv> {}

      Source: http://docs.hhvm.com/manual/en/class.hack.indexishtktv.php

      I actually don’t know how it works. Look att the function signatures for ImmMap. This interface might only be for parameter annotation and not for creating your own Indexish objects.

  2. Hello Tobias Nyholm,

    I am not getting exactly what it is ? and where we can you use this ?



Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>