3
list = { {a,b}, {c,d}, {e,g} }

How to efficiently get

{ f[a,b], f[c,d], f[e,g] }

I tried various combinations using @, /@ together with Sequence, like

f[Sequence[#]] /@ list

but no success.

Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50

4 Answers4

7

Turning a comment into an answer.

f@@@list

The long form of this is

Apply[f,list,{1}]

and it can be generalized to depth d by

Apply[f,list,{d}]
Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
4
list = {{a, b}, {c, d}, {e, g}};

Apply[f, list, {1}]

Or short hand of this

f@@@list

Both gives

{ f[a,b], f[c,d], f[e,g] }

OkkesDulgerci
  • 10,716
  • 1
  • 19
  • 38
3
f[Sequence @@ #] & /@ list

Finally worked. But is this the best(most efficient) way?

Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50
1

You can also do

Map[f[#[[1]], #[[2]]] &, list]
{f[a, b], f[c, d], f[e, g]}

Or more compactly:

f[#[[1]], #[[2]]] & /@ list
Rudy Potter
  • 2,553
  • 8
  • 20