1

Currently, if I want to apply the transformation effected by a function of a single variables f to all values in a list, I use makelist, e.g.

f(x):= x^2;
aList: [1,2,3,4];
f_aList: makelist(f(aList[i]), i, length(aList));

I have to do this so often that I was about to write a quick function that would handle this, e.g.

apply2list(f, aList):=
   block([f:f, aList:aList],
   makelist(f(aList[i]), i, length(aList))
   );

for any single variable function f and list aList, but wondered if there was some way of doing this, already built in?

Rax Adaam
  • 790
  • 3
  • 11

0 Answers0