The function calls count, so this is what you need to wrap. You can do either
const count = instrument(n => n && 1 + count(n-1));
or
let count = n => n && 1 + count(n-1);
count = instrument(count);
For everything else, you will need to dynamically insert a function for a recursive call into a tool function, similar to how Y combinator does it.
source
share