---
title: "ComapApply"
language: "en"
type: "Symbol"
summary: "ComapApply[{f1, f2, ...}, expr] gives {Apply[f1, expr], Apply[f2, expr], ...}. ComapApply[fs] represents an operator form of ComapApply that can be applied to an expression."
keywords: 
- applying lists of functions to lists
- simultaneous application
canonical_url: "https://reference.wolfram.com/language/ref/ComapApply.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Functional Programming"
    link: "https://reference.wolfram.com/language/guide/FunctionalProgramming.en.md"
  - 
    title: "Function Composition & Operator Forms"
    link: "https://reference.wolfram.com/language/guide/FunctionCompositionAndOperatorForms.en.md"
  - 
    title: "Structural Operations on Expressions"
    link: "https://reference.wolfram.com/language/guide/StructuralOperationsOnExpressions.en.md"
related_functions: 
  - 
    title: "MapApply"
    link: "https://reference.wolfram.com/language/ref/MapApply.en.md"
  - 
    title: "Comap"
    link: "https://reference.wolfram.com/language/ref/Comap.en.md"
  - 
    title: "Through"
    link: "https://reference.wolfram.com/language/ref/Through.en.md"
  - 
    title: "Construct"
    link: "https://reference.wolfram.com/language/ref/Construct.en.md"
  - 
    title: "Apply"
    link: "https://reference.wolfram.com/language/ref/Apply.en.md"
  - 
    title: "Map"
    link: "https://reference.wolfram.com/language/ref/Map.en.md"
  - 
    title: "MapThread"
    link: "https://reference.wolfram.com/language/ref/MapThread.en.md"
  - 
    title: "Operate"
    link: "https://reference.wolfram.com/language/ref/Operate.en.md"
  - 
    title: "Thread"
    link: "https://reference.wolfram.com/language/ref/Thread.en.md"
related_tutorials: 
  - 
    title: "Applying Functions to Parts of Expressions"
    link: "https://reference.wolfram.com/language/tutorial/FunctionalOperations.en.md"
---
[EXPERIMENTAL]

# ComapApply

ComapApply[{f1, f2, …}, expr] gives {Apply[f1, expr], Apply[f2, expr], …}.

ComapApply[fs] represents an operator form of ComapApply that can be applied to an expression.

## Details and Options

* ``ComapApply`` is typically used to apply each of a list of functions to the same sequence of arguments. »

* With the option setting ``Heads -> True``, ``ComapApply`` includes heads of expressions and their parts. »

* ``ComapApply`` always effectively constructs a complete new expression and then evaluates it. »

* The head of ``fs`` in ``ComapApply[fs, expr]`` need not be ``List``.

* If ``fs`` is an ``Association`` object, ``ComapApply[fs, expr]`` replaces the head of ``expr`` with the values in the association. »

* ``ComapApply[fs][expr]`` is equivalent to ``ComapApply[fs, expr]``.

* ``Parallelize[ComapApply[fs, expr]]`` computes ``ComapApply[fs, expr]`` in parallel on all subkernels. »

---

## Examples (15)

### Basic Examples (3)

Replace the head of ``{1, 2}`` with each element of a list:

```wl
In[1]:= ComapApply[{f, g, h}, {1, 2}]

Out[1]= {f[1, 2], g[1, 2], h[1, 2]}
```

---

Use the operator form of ``ComapApply`` :

```wl
In[1]:= ComapApply[{f, g, h}][{1, 2, 3}]

Out[1]= {f[1, 2, 3], g[1, 2, 3], h[1, 2, 3]}
```

---

Replace the head of an expression with the values in an association:

```wl
In[1]:= ComapApply[<|"a" -> f, "b" -> g, "c" -> h|>, {x, y}]

Out[1]= <|"a" -> f[x, y], "b" -> g[x, y], "c" -> h[x, y]|>
```

### Scope (3)

Use explicit pure functions:

```wl
In[1]:= ComapApply[{1 + f[#, #2]&, 2 + g[#, #2]&, 3 + h[#, #2]&}, {1, 2}]

Out[1]= {1 + f[1, 2], 2 + g[1, 2], 3 + h[1, 2]}

In[2]:= ComapApply[{{x, y} |-> x + y, {x, y} |-> x y}, {3, 4}]

Out[2]= {7, 12}
```

---

``ComapApply`` can be used on expressions with any head:

```wl
In[1]:= ComapApply[f[a, b], g[x, y]]

Out[1]= f[a[x, y], b[x, y]]
```

---

Replace the head of an expression with the values of an ``Association`` :

```wl
In[1]:= ComapApply[<|"a" -> f, "b" -> g|>, {1, 2}]

Out[1]= <|"a" -> f[1, 2], "b" -> g[1, 2]|>
```

### Options (1)

#### Heads (1)

Apply inside the head as well as arguments:

```wl
In[1]:= ComapApply[f[g], {x}, Heads -> True]

Out[1]= f[x][g[x]]

In[2]:= ComapApply[f[g], {x}]

Out[2]= f[g[x]]
```

### Properties & Relations (8)

``ComapApply`` successively replaces the head of an expression with the parts of another expression:

```wl
In[1]:= ComapApply[{f, g, h}, head[x, y]]

Out[1]= {f[x, y], g[x, y], h[x, y]}
```

``MapApply`` replaces the head of each part of an expression with another expression:

```wl
In[2]:= MapApply[f, {head[x, y], head[a, b], immaterial[1, 2]}]

Out[2]= {f[x, y], f[a, b], f[1, 2]}
```

---

``Through[p[f, g, …][x, y, …]]`` is equivalent to ``ComapApply[p[f, g, …], {x, y, …}]`` :

```wl
In[1]:= Through[{f, g, h}[x, y, z]]

Out[1]= {f[x, y, z], g[x, y, z], h[x, y, z]}

In[2]:= ComapApply[{f, g, h}, {x, y, z}]

Out[2]= {f[x, y, z], g[x, y, z], h[x, y, z]}
```

Compare this to the operator form of ``ComapApply`` :

```wl
In[3]:= ComapApply[{f, g, h}][{x, y, z}]

Out[3]= {f[x, y, z], g[x, y, z], h[x, y, z]}
```

---

``ComapApply[p[f, g, …], {x, y, …}]`` can be used even when ``p[f, g, …][x, y, …]`` has a value:

```wl
In[1]:= ComapApply[<|"a" -> f, "b" -> g|>, {x, y, z}]

Out[1]= <|"a" -> f[x, y, z], "b" -> g[x, y, z]|>
```

When ``p[f, g, …][x, y, …]`` has a value, ``Through`` cannot be used:

```wl
In[2]:= <|"a" -> f, "b" -> g|>[x, y, z]

Out[2]= Missing["KeyAbsent", x]

In[3]:= Through[<|"a" -> f, "b" -> g|>[x, y, z]]

Out[3]= Through[Missing["KeyAbsent", x]]
```

---

``ComapApply[{f1, f2, …}, expr]`` is equivalent to ``Map[f |-> Apply[f, expr], {f1, f2, …}]`` when the ``fi`` have no attributes:

```wl
In[1]:= ComapApply[{f, g, h}, {x, y}]

Out[1]= {f[x, y], g[x, y], h[x, y]}

In[2]:= Map[e |-> Apply[e, {x, y}], {f, g, h}]

Out[2]= {f[x, y], g[x, y], h[x, y]}
```

---

``ComapApply`` can replace the head of an expression with parts inside held expressions without allowing evaluation to proceed:

```wl
In[1]:= ComapApply[Hold[Plus, Times], {2, 3, 4}]

Out[1]= Hold[2 + 3 + 4, 2 3 4]
```

Use ``ReleaseHold`` to allow evaluation to proceed:

```wl
In[2]:= ReleaseHold[{%}]

Out[2]= {9, 24}
```

If only some arguments are held, only those arguments will not evaluate further:

```wl
In[3]:= SetAttributes[h, HoldRest]

In[4]:= ComapApply[h[Plus, Times], {2, 3, 4}]

Out[4]= h[9, 2 3 4]
```

---

Use ``Unevaluated`` to replace the head of an expression with different expressions without evaluating it first:

```wl
In[1]:= ComapApply[{f, g}, Unevaluated[a + b + a]]

Out[1]= {f[a, b, a], g[a, b, a]}
```

The expression is evaluated first by default:

```wl
In[2]:= ComapApply[{f, g}, a + b + a]

Out[2]= {f[2 a, b], g[2 a, b]}
```

---

Use ``Unevaluated`` to replace the head of an expression with the parts of an expression without evaluating it first:

```wl
In[1]:= ComapApply[Unevaluated[f g f], {1, 2}]

Out[1]= f[1, 2]^2 g[1, 2]
```

The expression is evaluated first by default:

```wl
In[2]:= ComapApply[f g f, {1, 2}]

Out[2]= f^2[1, 2] g[1, 2]
```

---

``ComapApply`` can be parallelized automatically:

```wl
In[1]:= Parallelize[ComapApply[{f, g, h}, {1, 2}]]

Out[1]= {f[1, 2], g[1, 2], h[1, 2]}
```

## See Also

* [`MapApply`](https://reference.wolfram.com/language/ref/MapApply.en.md)
* [`Comap`](https://reference.wolfram.com/language/ref/Comap.en.md)
* [`Through`](https://reference.wolfram.com/language/ref/Through.en.md)
* [`Construct`](https://reference.wolfram.com/language/ref/Construct.en.md)
* [`Apply`](https://reference.wolfram.com/language/ref/Apply.en.md)
* [`Map`](https://reference.wolfram.com/language/ref/Map.en.md)
* [`MapThread`](https://reference.wolfram.com/language/ref/MapThread.en.md)
* [`Operate`](https://reference.wolfram.com/language/ref/Operate.en.md)
* [`Thread`](https://reference.wolfram.com/language/ref/Thread.en.md)

## Tech Notes

* [Applying Functions to Parts of Expressions](https://reference.wolfram.com/language/tutorial/FunctionalOperations.en.md)

## Related Guides

* [Functional Programming](https://reference.wolfram.com/language/guide/FunctionalProgramming.en.md)
* [Function Composition & Operator Forms](https://reference.wolfram.com/language/guide/FunctionCompositionAndOperatorForms.en.md)
* [Structural Operations on Expressions](https://reference.wolfram.com/language/guide/StructuralOperationsOnExpressions.en.md)

## History

* [Introduced in 2024 (14.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn140.en.md)