Through[(Max - Min)[#]] & @ {1, 2, 3, 4, 5}
gives
5 + (-Min)[{1, 2, 3, 4, 5}]
Of course I can work around by
(Max[#] - Min[#]) & @ {1, 2, 3, 4, 5}
to achieve the desired result
4
But I wonder why Through
does not work with Subtract
and if there is a direct way to use it.
Edit:
After reading the answers, I see the problem is actually from Times
failing to play the role of an operator.
Subtract[Max, Min] // FullForm
gives
Plus[Max, Times[-1, Min]]
Here Times
takes a number -1
and a function Min
as arguments and is expected to return a function just like what an operator should do, which unfortunately is not the case.
To solve by doing the operator's job manually:
Composition[Times[-1, #] &, Min]
and for the example:
Through[Plus[Max, Composition[Times[-1, #] &, Min]][{1, 2, 3, 4, 5}]]
Max + Min // FullForm
andMax - Min // FullForm
$\endgroup$