HH\Set::getIterator

Description

public function getIterator(): KeyedIterator<mixed,Tv>

Returns an iterator that points to beginning of the current Set.

Return Values

Examples

This example shows how to get an iterator from a Set and how to consume it:

<?hh

namespace Hack\UserDocumentation\API\Examples\Set\GetIterator;

$s = Set {'red', 'green', 'blue', 'yellow'};

// Get an iterator for the Set of colors
$iterator = $s->getIterator();

// Print each color using the iterator
while ($iterator->valid()) {
  echo $iterator->current()."\n";
  $iterator->next();
}
Output
red
green
blue
yellow