# How to apply the multiple composite functions to a list?

A minimum example is this:

ls = {1 + I, 2 - I};
Max@Re[ls]
Min@Im[ls]
#[ls] & /@ {Max@Re, Min@Im} (*want {2, -1}*)


The result is:

{{1, 2}, {1, -1}}


I don't know why is this..

• @ does not denote function composition. It denotes function applications. f@g[x] is not (f@g)[x] but f@(g[x]), merely a different notation for f[g[x]]. Commented Apr 7, 2020 at 9:41
• You could just do {Max@Re[#], Min@Im@#} &@ls applying your function to ls instead of mapping it. Commented Apr 7, 2020 at 14:59
• @Szabolcs But Max[Re[ls]] gives just a number, why need composite? Also Max@Re[ls] gives a number Commented Apr 8, 2020 at 3:54

For a minimal change in your code, you can replace @ with Composition (@*)

#[ls] & /@ {Max@*Re, Min@*Im}

 {2, -1}


Consider also Through:

Through @ {Max @* Re, Min @* Im} @ ls

{2, -1}


Aside: Why your code gives {{1, 2}, {1, -1}}:

Trace[#[ls] & /@ {Max@Re, Min@Im}] // Column


Notice that Max@Re is replaced with Re and Min@Im is replaced with Im in the very first step of evaluation.

• If you can further add the reason why we need composite functions, the answer would be better. For example, why Max@Re[ls] Min@Im[ls] work as expected but not work when using Apply? Commented Apr 8, 2020 at 3:56
• @anoffercan'trefuse, added a note re why you get {{1, 2}, {1, -1}} if you use {Max@Re, Min@Im} instead of {Max@*Re, Min@*Im} or {Max@Re@#&, Min@Im@#&}
– kglr
Commented Apr 8, 2020 at 15:46
Map[{Max[Re[#]], Min[Im[#]]} &, ls, {0}]


Gives

{2, -1}


From help on Map

Level 0 corresponds to the whole expression.

ls = {1 + I, 2 - I};


Using Comap (new in 14.0)

Comap[{Max @* Re, Min @* Im}] @ ls


{2, -1}

ls = {1 + I, 2 - I};

Query[{Max @* Re, Min @* Im}] @ ls


{2, -1}

ls = {1 + I, 2 - I};


Another way using Thread:

Last@Activate@#1@#2 & @@@ Thread[{{Max@Re, Min@Im}, Inactive[ls]}]


Result:

{2, -1}