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.
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.
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}]
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] }
f[Sequence @@ #] & /@ list
Finally worked. But is this the best(most efficient) way?
f@@@list
– OkkesDulgerci
Jun 14 '18 at 17:31
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
f@@@list..... – Henrik Schumacher Jun 14 '18 at 17:15Applyto the 1st level. – Αλέξανδρος Ζεγγ Jun 15 '18 at 09:22