# How to use Apply and Map properly in this situation? [duplicate]

So this does what I want:

#1 <> #2 &["♠", "A"]

♠A


The output is fine. How do I quickly apply this to the list

{{"♠", "A"}, {"♢", "A"}, {"♣", "A"}, {"♡", "A"}}


So that I can combined all of the suits with the Aces? I have tried a mixture of "/", "@" and "/@". None of these worked.

• You want @@@ -- apply at level 1. – jjc385 Nov 4 '17 at 7:06
• @jjc385 THANKS! Finally, I got it! (#1 <> ToString[#2] &) @@@ carddeck – Chen Stats Yu Nov 4 '17 at 7:11
• Happy to help. Note that if carddeck is a nested list like the list given in the question (with all sublist elements being strings), you shouldn't need the ToString in there. – jjc385 Nov 4 '17 at 7:17

You want to Apply your function at level 1 in the list :

#1 <> #2 & @@@ {{"♠", "A"}, {"♢", "A"}, {"♣", "A"}, {"♡", "A"}}

{"♠A", "♢A", "♣A", "♡A"}


As mentioned at the very top of the docs for Apply, f @@@ expr is is syntactic sugar for Apply[ f, expr, {1} ], and has the same effect as Apply[ f, # ]& /@ expr.

Note that #1 <> #2 & parses as StringJoin[#1,#2]&, for which you might as well just use StringJoin :

StringJoin @@@ {{"♠", "A"}, {"♢", "A"}, {"♣", "A"}, {"♡", "A"}}

{"♠A", "♢A", "♣A", "♡A"}