# Is there a simple way to convert {a,b,c} to a,b,c?

I need to use:

Composition[G][x]


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]?

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


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

Apply is designed for this purpose:

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


Or

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

• Shorthand for Apply is @@. E.g. (Composition @@ {a,b,c})[x] or x // Composition @@ {a,b,c}. Commented Nov 20, 2021 at 11:52
• @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. Commented Nov 20, 2021 at 21:24

With:

alist = {a, b, c}


A variant using Fold could be:

Fold[Composition, alist][x]


a[b[c[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.

• 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]] Commented Nov 20, 2021 at 15:52
• A variation of this solution is Fold[ReverseApplied[Construct], x, Reverse@{a, b, c}]. 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:

Composition[##][x]&@@#&/@j


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

• Or Composition[##][x]&@@@j if always a list of lists of functions. :) Commented Nov 21, 2021 at 14:09
• A simpler version is: #[x]& /@ Composition@@@j Commented Nov 22, 2021 at 15:34