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

namespace HH;

function meth_caller(
  string $cls_name,
  string $meth_name,

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:

$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:


  • string $cls_name
  • string $meth_name

Return Values

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