I need to use:


in the elements of the following list:

j = {{a, b, c}, {c, b, a}};

That is, I could do:

Table[Composition[j[[n]]][x], {n, 1, 2}]

which produces:

{{a, b, c}[x], {c, b, a}[x]}

but Composition doesn't seem to work with lists. I can't evaluate Composition[{a,b,c}][x]; it accepts only Composition[a,b,c][x].

Is there a simple way to convert Composition[{a,b,c}] to Composition[a,b,c]?


4 Answers 4

lis = {a, b, c}
Composition[Sequence @@ lis][x]

Mathematica graphics

  • $\begingroup$ Doesn't just Composition @@ lis work just fine? $\endgroup$
    – LSpice
    Commented Nov 22, 2021 at 2:12
  • 4
    $\begingroup$ @LSpice yes, and it needs to be enclosed by parentheses before applying to an argument, e.g. (Composition @@ lis)[x] $\endgroup$
    – polfosol
    Commented Nov 22, 2021 at 15:27
  • $\begingroup$ @polfosol or just x // Composition @@ lis $\endgroup$ Commented Nov 29, 2021 at 18:49

Apply is designed for this purpose:

Apply[Composition][{a, b, c}][x]
(*  a[b[c[x]]]  *)


Apply[Composition, {a, b, c}][x]
  • 2
    $\begingroup$ Shorthand for Apply is @@. E.g. (Composition @@ {a,b,c})[x] or x // Composition @@ {a,b,c}. $\endgroup$
    – Džuris
    Commented Nov 20, 2021 at 11:52
  • 1
    $\begingroup$ @Džuris Yep, I usually use @@. Except, a personal preference, I dislike parentheses, which led me to avoid @@ in these situations. With command completion, the length of typing is about the same, and no parentheses feels easier to type & read for me. $\endgroup$
    – Michael E2
    Commented Nov 20, 2021 at 21:24


alist = {a, b, c}

A variant using Fold could be:

Fold[Composition, alist][x]


Another variant using ComposeList could be:

ComposeList[Reverse@alist, x]

{x, c[x], b[c[x]], a[b[c[x]]]}

from which the last item can be extracted.

  • 4
    $\begingroup$ x // Fold[Composition] /@ {{a, b, c}, {c, b, a}} // Through shows how naturally Fold and Composition can express the solution to OP's problem. Or myFuncList = Fold[Composition] /@ {{a, b, c}, {c, b, a}}; which can be used later, either as individual functions or in Through[myFuncList[x]] $\endgroup$
    – Michael E2
    Commented Nov 20, 2021 at 15:52
  • 1
    $\begingroup$ A variation of this solution is Fold[ReverseApplied[Construct], x, Reverse@{a, b, c}]. $\endgroup$ Commented Dec 9, 2021 at 20:36

Since no one seems to have answered how to Apply Composition to a List like j given by OP, here it is:



  • 5
    $\begingroup$ Or Composition[##][x]&@@@j if always a list of lists of functions. :) $\endgroup$
    – Michael E2
    Commented Nov 21, 2021 at 14:09
  • 1
    $\begingroup$ A simpler version is: #[x]& /@ Composition@@@j $\endgroup$
    – polfosol
    Commented Nov 22, 2021 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.