HH\Set::toSet

Description

public function toSet(): Set<Tv>

Returns a deep copy of the current Set.

Return Values

Examples

This example shows that toSet returns a deep copy of the Set:

<?hh

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

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

// Make a deep copy of Set $s
$s2 = $s->toSet();

// Modify $s2 by adding an element
$s2->add('purple');
var_dump($s2);

// The original Set $s doesn't include 'purple'
var_dump($s);
Output
object(HH\Set)#2 (5) {
  string(3) "red"
  string(5) "green"
  string(4) "blue"
  string(6) "yellow"
  string(6) "purple"
}
object(HH\Set)#1 (4) {
  string(3) "red"
  string(5) "green"
  string(4) "blue"
  string(6) "yellow"
}