HH\Set::items

Returns an Iterable view of the current Set.

Description

public function items(): Iterable<Tv>

Returns an Iterable view of the current Set.

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

Return Values

Examples

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

<?hh

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

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

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

// Add another color to the original Set $s
$s->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