HH\meth_caller

Like [fun](/hack/reference/function/HH

Description

function meth_caller(
  string $class,
  string $method,
)

fun/), but with the purpose of calling an instance method on any object of a certain class.

With fun you'd pass in something like 'count' and it'd call count($x) on whatever you pass in. This, rather, will call $x->count() for whatever object $x you pass in, which must be of type $class.

For example:

<?hh
$v = Vector {
  Vector {1, 2, 3},
  Vector {1, 2}
};
$v->map(meth_caller('Vector', 'count'))  // returns Vector {3, 2}

...calls the count method on the inner vectors, and returns a vector of the results of that.

See also:

Parameters

  • $class The class of the method to call. Must be a constant string.
  • $method The method of the class that will be called. Must be a constant string.

Return Values

  • A - callback which will call $method when invoked.