2 // Copyright 2004-present Facebook. All Rights Reserved.
4 function nullthrows
<T
>(?T
$x): T
{
8 final class XorParam
<Tx
, Ty
> {
9 private function __construct(private ?Tx
$x, private ?Ty
$y) {
11 ($x === null) !== ($y === null),
12 "Exactly one input value must be null!",
16 public static function fromFirstValue(?Tx
$x, ?Ty
$y): XorParam
<Tx
, Ty
> {
18 return new XorParam($x, null);
20 return new XorParam(null, $y);
23 public function getX(): ?Tx
{
27 public function atX(): Tx
{
28 return nullthrows($this->x
);
31 public function getY(): ?Ty
{
35 public function atY(): Ty
{
36 return nullthrows($this->y
);
39 // Returns the single non-null value
40 // TODO: is it possible to augment the type info within the generics so we
41 // can type this return value?
42 public function getValue(): mixed {
43 $z = $this->x ??
$this->y
;