There is no direct notation for anonymous slot references to outer pure function arguments (named arguments to Function
having been ruled out). But we can use the higher-order function OperatorApplied as a way to avoid explicit argument naming:
OperatorApplied[Take, 2][#] /@ Range@Length[#] & /@ test(* {{{4}, {4,2}, {4,2,2}}, {{9}, {9,1}, {9,1,5}}, {{5}, {5,2}, {5,2,9}, {5,2,9,3}}, {{5}, {5,2}, {5,2,7}, {5,2,7,1}, {5,2,7,1,1}}} *)
or, equivalently:
OperatorApplied[Take[#2, #]&][#] /@ Range@Length[#] & /@ test
For this particular case, CurryApplied could be substituted for OperatorApplied
. We could also use Curry (my old favourite) but it has been deprecated and slated for removal some day.
See (197168) for more discussion of this currying technique within nested pure functions.
Just For Fun
If Wolfram Language had some kind of forking operator, we could dispense with slot notation for this example and write in point-free form:
fork[f_][g_, h_][x_] = f[g[x], h[x]]test // Map@fork[Map][Curry[Take,2], Range@*Length](* {{{4}, {4,2}, {4,2,2}}, {{9}, {9,1}, {9,1,5}}, {{5}, {5,2}, {5,2,9}, {5,2,9,3}}, {{5}, {5,2}, {5,2,7}, {5,2,7,1}, {5,2,7,1,1}}} *)
The Query sublanguage has something resembling a fork operator, so we can write:
test // Query[All, Apply[Map]@*{Curry[Take, 2], Range@*Length}]