Nested pure functions can be messy, code length wise and syntax wise. It seems that the ampersand (&) in pure functions is always either proceeded by nothing:
list // SortBy[#, Last[#]] &
Select[list, First[#]==="potato" &]
or is proceeded by a special operator:
{#, f[#]} & @ item
g[#,f[#]] & /@ list
(#1 -> #2) & @@@ list
f[g[#1, #2], h[#1, #2]] & [a, b]
Which leads me to wonder—at the risk of being off topic—is it feasible for argument names to be used in the shorthand notation by having it precede the ampersand symbol? Or is there some unforeseen use case in Mathematica which makes this impossible? Hopefully the yes-no question will make it on topic.
To illustrate this, here are some methods of nesting pure functions, the first two are from kglr's linked answer above, and the last is based off Henrik Schumacher's comment:
Function[{x}, Select[x, # == Nearest[x, 4.][[1]] &]] /@ lists
With[{x = Nearest[#1, 4.`][[1]]}, Select[#1, # == x &]] & /@ lists
# /. x_ :> Select[x, # == Nearest[x, 4.][[1]] &] & /@ lists
(x \[Function] Select[x, # == Nearest[x, 4.][[1]] &]) /@ lists
Here is the same code using the hypothetical method:
Select[x, # == Nearest[x, 4.][[1]] &] & x /@ lists
and here is how multiple arguments would look:
{f[x], g[y]} & {x, y} @@@ lists
I didn't include patterns as it seems like Module
, With
and the shorthand method are not able to use them.
a & b
currently evaluates tob (a &)
orTimes[b, Function[a]]
in full form. Edit: Was responding to deleted comment abouta & b
potentially being evaluated asFunction[b, a]
. $\endgroup$\[Function]
ofFunction
? $\endgroup$Function
with the Notation package but why would you want to obfuscate your code like this? $\endgroup$