Message Boards Message Boards

0
|
2559 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[Solved] Mapping lists to pure functions

Posted 4 years ago

Hi all,

I want to achieve the following:

I have a list

l = {{"First", {{"1", "1"}, {"1", "2"}}}, {"Second", {{"2", 
      "1"}, {"2", "2"}}}};

and some pure function

f[#1, #2] &

I want the argument #1 to be the first string and #2 the list that follows. Like so:

f["First",{{"1", "1"}, {"1", "2"}}]

My guess is, that the way to go would be to Apply[] the function to a Map[] of the list. Is that the correct thinking? I've tried a lot of combinations and nothing works. Also, in general, how would I use the @@ and /@ operators in a row?

Thank you and all the best

Timo

POSTED BY: Timo Kuchheuser
2 Replies

There are a variety of ways of doing this:

l = {{"First", {{"1", "1"}, {"1", "2"}}}, {"Second", {{"2", "1"}, {"2", "2"}}}};
f @@@ l
Apply[f, l, {1}]
Apply[f] /@ l
Map[Apply[f]]@l
Map[Apply[f]][l]
POSTED BY: Sander Huisman

Nice!

Thank you!

POSTED BY: Timo Kuchheuser
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