Message Boards Message Boards

1
|
9149 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Map/Apply over a list with optional arguments

Posted 10 years ago
Hello,

I have a list
x = {a, b, c, d}
and can be mapped to the function using
Map[f, x]
Say if the function takes two arguments, is this possible to get
{f[arg1,a], f[arg1,b], f[arg1,c], f[arg1,d]}

many thanks!
POSTED BY: Casper YC
3 Replies
Thread works, too.
In[1]:= x = {a, b, c, d};                                                         

In[2]:= Thread[ f[arg1, x] ]                                                      
Out[2]= {f[arg1, a], f[arg1, b], f[arg1, c], f[arg1, d]}

 http://reference.wolfram.com/mathematica/ref/Thread.html
POSTED BY: Bruce Miller
The pure function approach is usually best. If for some reason you want to avoid that, could curry the thing as below.
f[arg_][x_] := f[arg,x]
Now you can do
Map[f[arg1], list]
POSTED BY: Daniel Lichtblau
f[arg1,#]&/@x
Here I used an anonymous function.  Note that Map[f,x] is the same as:
f/@x
POSTED BY: Terrence Honan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract