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.

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.

3 Comments

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

    Reply
    • 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 ?

    Thanks

    Reply

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>