HH\Vector::items

Returns an Iterable view of the current Vector.

Description

public function items(): Iterable<Tv>

Returns an Iterable view of the current Vector.

The Iterable returned is one that produces the values from the current Vector.

Return Values

Examples

This example shows that items() returns an Iterable view of the Vector. The Iterable will produce the values of the Vector at the time it's iterated.

<?hh

namespace Hack\UserDocumentation\API\Examples\Vector\Items;

$v = Vector {'red', 'green', 'blue', 'yellow'};

// Get an Iterable view of the Vector
$iterable = $v->items();

// Add another color to the original Vector $v
$v->add('purple');

// Print each color using $iterable
foreach ($iterable as $color) {
  echo $color."\n";
}

// This wouldn't work because the Iterable interface is read-only:
// $iterable->add('orange');
Output
red
green
blue
yellow
purple