Generating composed operators using Table

Given an operator with two argumentsf[#1,#2]& and some positive (evaluated) integer n, I want to generate the operator f[...f[f[#,1],2]...,n]&.

I triedComposition[Sequence@@Table[f[#,i]&,{i,1,n}]], but Table does not return what I would expect when the expression used is an operator. More precisely, Table[f[#,i]&,{i,1,n}] returns {f[#1,i]&,...,f[#1,i]}, instead of {f[#1,1]&,...,f[#1,n]&}.

A solution to my original problem is thus found if given f[#1,#2]& and n I could generate {f[#1,1]&,...,f[#1,n]&}.

Any help?

• Fold[f,#,Range[5]]& ? Commented Mar 11, 2021 at 11:57
• That's it. I feel stupid for asking now. Thanks! Commented Mar 11, 2021 at 12:04
• Fold is powerful,and I am not so familiar with it. Commented Mar 11, 2021 at 12:06

Fold[f,#,Range[5]]&


We have given the answer to this question, here we just add another example which surprise me and indicate that Fold is so powerful.

Fold[Sqrt[#1] + #2 &,Reverse@Range[10]]


$$1+\sqrt{2+\sqrt{3+\sqrt{4+\sqrt{5+\sqrt{6+\sqrt{7+\sqrt{8+\sqrt{9+\sqrt{10}}}}}}}}}$$