HH\Pair::toSet

Returns a Set with the values of the current Pair

Description

public function toSet(): Set<mixed>

Return Values

Examples

This example shows that converting a Pair to a Set also removes duplicate values:

<?hh

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

// This Pair contains 'foo' twice
$p = Pair {'foo', 'foo'};

$s = $p->toSet();
var_dump($s);
Output
object(HH\Set)#2 (1) {
  string(3) "foo"
}

This example shows that converting a Pair to a Set will throw a fatal error if the Pair contains a value that's not a string or an int:

<?hh

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

$p = Pair {'foo', -1.5};

// Fatal error will be thrown here
$s = $p->toSet();

var_dump($s);
Output
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Only integer values and string values may be used with Sets' in /user-documentation/api-examples/class.Pair/toSet/002-runtime-fatal.php:8
Stack trace:
#0 /user-documentation/api-examples/class.Pair/toSet/002-runtime-fatal.php(8): HH\Pair->toSet()
#1 {main}