Back to Hhvm

FromItems

hphp/hack/manual/apis/Classes/HH/Set/fromItems.md

latest1.6 KB
Original Source

:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::

Creates a Set from the given Traversable, or an empty Set if null is passed

Hack
public static function fromItems(
  ?Traversable<Tv> $iterable,
): Set<Tv>;

This is the static method version of the Set::__construct() constructor.

Parameters

Returns

Examples

basic-usage.hack
// Create a new Set from an array
$s = Set::fromItems(varray['red', 'green', 'red', 'blue', 'blue', 'yellow']);
\var_dump($s);

// Create a new Set from a Vector
$s = Set::fromItems(Vector {'red', 'green', 'red', 'blue', 'blue', 'yellow'});
\var_dump($s);

// Create a new Set from the values of a Map
$s = Set::fromItems(Map {
  'red1' => 'red',
  'green' => 'green',
  'red2' => 'red',
  'blue1' => 'blue',
  'blue2' => 'blue',
  'yellow' => 'yellow',
});
\var_dump($s);
<!-- HHAPIDOC -->