Onion method into function?

I am using the Onion method for a problem I’ve previously posted about (e.g., Using the onion method in occupancy model hierarchical model - Modeling - The Stan Forums (mc-stan.org)).

Is it possible to encapsulate the “function” to be like the lkj_corr_cholesky() function? I have created a simple function (here: stan_files/scale_cholesky_factor.stan · main · UMESC / quant-ecology / occStan_hm · GitLab (usgs.gov)) but there are still several calls outside of the function.

I would be willing to take a stab, but I cannot find the current lkj_corr_cholesky() function in the GitHub page ( e.g., Search · lkj_corr_cholesky (github.com)). I am curious about how lkj_corr_cholesky() handles probabilities.

In summary my two main questions:

  1. Where is the source code for lkj_corr_cholesky()?
  2. How hard would it be to put the onion method into a function like lkj_corr_cholesky()?

The source code for the lkj_corr_cholkesky distribution lives in the Math library here