# Using Through at lowest

This works

Through[{#*2 &, #*8 &}[a]]

{2 a, 8 a}


But if I want to generalize to a 2 dimensional array of functions like this

Through[{{#*2 &, #*8 &}, {#*3 &, #*5 &}}[a]]


It doesn't work. I've tried to add a third argument to Through such as 1 or 2 or {1,1} and this doesn't help. To be clear, I know how to work around this, but I just don't understand why it isn't easy to generalize through to a general array of functions.

• Working around it: Through[#[a]] & /@ {{#*2 &, #*8 &}, {#*3 &, #*5 &}}
– Syed
Commented May 2, 2023 at 15:58
• {{#*2, #*8}, {#*3, #*5}} &[a] ? In other words, apply one function with the required structure? Commented May 2, 2023 at 16:08
• Thank for the work arounds. That is currently what I have in my code. However, I'm just frustrated that Through doesn't have an obvious extension to arrays greater than one dimension. Commented May 2, 2023 at 17:04
• Through doesn't assume that the head of the head is List. And it certainly doesn't assume that the head is a full matrix. So, there would need to be some way to recursively find the same head-head symbol at all levels of the head structure and then figure out how it's supposed to be applied. That seems very complicated and not as semantically clear as the current Through definition. Probably better to go with one of the Map- or Apply-related functions. Commented May 2, 2023 at 17:23
• It is unfortunate this question is closed because several creative approaches to the problem appeared over the last few hours. Commented May 3, 2023 at 15:35

Through/@Through[{{#*2 &, #*8 &}, {#*3 &, #*5 &}}[a]]

(*{{2*a, 8*a}, {3*a, 5*a}} *)


(2)

Through[{{f, g},{x,y}}[a]]
(* {{f, g}[a], {x, y}[a]} *)


and:

Through/@Through[{{f, g},{x,y}}[a]]

(* {{f[a], g[a]}, {x[a], y[a]}} *)


I propose :

Map[#[a] &, {{#*2 &, #*8 &}, {#*3 &, #*5 &}}, {2}]


{{2 a, 8 a}, {3 a, 5 a}}

Though I have never used it.

• My objection to this workout around is that it isn't readable, in the sense that I can't just look at it and red it like an english sentence. Commented May 2, 2023 at 19:54

Using Query

Query[{{#*2 &, #*8 &}, {#*3 &, #*5 &}}] @ a


{{2 a, 8 a}, {3 a, 5 a}}

Using Comap (new in 14.0)

Comap[{{#*2 &, #*8 &}, {#*3 &, #*5 &}}, a, {2}]


{{2 a, 8 a}, {3 a, 5 a}}

• Query is good since it work for the general cases. Commented May 9 at 0:39

I learn this from someone.

Clear[operator];

{{2 a, 8 a}, {3 a, 5 a}, {a, a, a}, a}.
Using Thread:
Apply[#1@#2&,Thread/@Thread[{{{#*2 &, #*8 &}, {#*3 &, #*5 &}},a}],{2}]

{{2 a,8 a},{3 a,5 a}}