Skip to content

Instantly share code, notes, and snippets.

@Crell
Created July 10, 2020 16:24
Show Gist options
  • Save Crell/1e8decec66e2200a6a91eb69e9d7f831 to your computer and use it in GitHub Desktop.
Save Crell/1e8decec66e2200a6a91eb69e9d7f831 to your computer and use it in GitHub Desktop.
enum Option {
case None = new class {};
case Some = new class($val) {
public function __construct(private $val) {}
public function value() { return $val; }
};
public function value{} { throw new TypeError; }
}
enum Option {
case None;
case Some = new Some($val);
public function value{} { throw new TypeError; }
}
class Some extends Option {
public function __construct(private $val) {}
public function value() { return $val; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment