3
$\begingroup$
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.

$\endgroup$
7
$\begingroup$

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}]
$\endgroup$
4
$\begingroup$
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] }

$\endgroup$
3
$\begingroup$
f[Sequence @@ #] & /@ list

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

$\endgroup$
  • 2
    $\begingroup$ As Henrik commented, this is the best(most efficient) way f@@@list $\endgroup$ – OkkesDulgerci Jun 14 '18 at 17:31
1
$\begingroup$

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
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.