I have an interface that looks like this.
interface Value {
public function accept<T>(ValueVisitor<T> $visitor): T;
}
Since there is only one method, I want to write a class which converts a closure into an instance of Value
.
final class ClosureValue implements Value {
public function __construct(
private (function<T>(ValueVisitor<T>): T) $f
) {}
public function accept<T>(ValueVisitor<T> $visitor): T {
$f = $this->f;
return $f($visitor);
}
}
However, the <T>
in the type function<T>(ValueVisitor<T>): T
is a syntax error. No matter where I put the <T>
, it wont parse.
How can I write this in Hack?