HH\Set::fromItems
Creates a Set
from the given Traversable
, or an empty Set
if null
is passed
public static function fromItems(
?Traversable<Tv> $iterable,
): Set<Tv>;
This is the static method version of the Set::__construct()
constructor.
Parameters
?
Traversable<Tv>
$iterable
Returns
Set<Tv>
- ASet
with the values from theTraversable
; or an emptySet
if theTraversable
isnull
.
Examples
// 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);