HH\Pair::toImmSet
Returns an immutable set (ImmSet
) with the values of the current Pair
public function toImmSet(): ImmSet<arraykey, mixed>;
Returns
ImmSet<arraykey, mixed>
- anImmSet
with the current values of the currentPair
.
Examples
This example shows that converting a Pair
to an ImmSet
also removes duplicate values:
// This Pair contains 'foo' twice
$p = Pair {'foo', 'foo'};
$imm_set = $p->toImmSet();
var_dump($imm_set);
object(HH\ImmSet)#2 (1) {
string(3) "foo"
}
This example shows that converting a Pair
to an ImmSet
will throw a fatal error if the Pair
contains a value that's not a string
or an int
:
$p = Pair {'foo', -1.5};
// Fatal error will be thrown here
$imm_set = $p->toImmSet();
var_dump($imm_set);
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/toImmSet/002-runtime-fatal.php:8
Stack trace:
#0 /user-documentation/api-examples/class.Pair/toImmSet/002-runtime-fatal.php(8): HH\Pair->toImmSet()
#1 {main}