# Perform Apply[] to a sum of objects

is there any way to use the Apply[] function to a sum of objects? By this I mean the following. We know that using Apply[] (@@) to an objects gives:

f@@{a}
f[a]


I'm wondering if there's a way of doing something like

(f+g)@@{a}
f[a]+g[a]


Does anyone knows anything about it? Thanks!

• Perhaps you require Through[Sequence@@@(f + g)@{a}] or Through[(f + g)[a]]? (or Sequence@@@(f + g)@{a}//Through) Sep 24, 2021 at 22:18
• #@a & /@ (f + g) Sep 25, 2021 at 2:34
• Also Through[(f + g)[a]] or Through[(f + g) @@ {a}] Sep 25, 2021 at 7:38
• Thanks! All these work!
– Einj
Sep 25, 2021 at 23:13

As of version 14.0, ComapApply is introduced:

ComapApply[f + g, {a}]
(* f[a] + g[a] *)

ComapApply[f + g]@{a}
(* f[a] + g[a] *)


BTW, if the object isn't a List {}, you can directly use Comap (also new in v14):

Comap[f + g, a]
(* f[a] + g[a] *)

Comap[f + g]@a
(* f[a] + g[a] *)


This is another way and an active effort to advertise the ThroughOperator that was developed by @Sjoerd Smit. This is rather new and I find it convenient.

To the extend of my knowledge it was first suggested in this answer.

fnctns = {f, g};
oprtr = ResourceFunction["ThroughOperator"][fnctns, Plus];


and then

oprtr /@ {a} /. List -> (# &)


• Does this accomplish anything that Though[(f+g)[a]] doesn't? Why should we rely on an external solution when an internal one exists? Jan 17, 2023 at 8:22
• @NajibIdrissi did you visit any of the links I provided? I am asking out of curiosity
– bmf
Jan 17, 2023 at 8:25
• Yes, I visited the links. Jan 17, 2023 at 8:36
• @NajibIdrissi in the second link there's this explanation in a comment Through[{f1, f2, f3}[5]] is annoying to map over lists, which is one of the main motivations I made ThroughOperator. Another reason is that Through[h[f1, f2][x]] sometimes suffers from order-of-evaluation issues that are difficult to circumvent which for me at least was enough to give it a go. Also, I just suggested this an alternative. I realize what the easiest way is.
– bmf
Jan 17, 2023 at 8:39
• Glad to see my function is being used :) Jan 17, 2023 at 12:57

Using Query

Query[{f, g} /* Total] @ a


f[a] + g[a]