2
$\begingroup$

This question already has an answer here:

Suppose I have a list of functions like:

listfun = { Sin, Cos, Tan } 

And suppose I want to map listfun to a single number Pi so that the result is,

result = { Sin[Pi], Cos[Pi], Tan[Pi] } = {0, -1, 0} 

How can I generate result above? Thanks!

$\endgroup$

marked as duplicate by Quantum_Oli, m_goldberg, Yves Klett, MarcoB, user9660 Jul 8 '16 at 12:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Does Through fit your needs? $\endgroup$ – Kuba Jul 8 '16 at 10:10
  • 6
    $\begingroup$ (83878) $\endgroup$ – Kuba Jul 8 '16 at 10:11
  • $\begingroup$ @Kuba Is there a builtin for #1[##2]& or similar? $\endgroup$ – Szabolcs Jul 8 '16 at 10:12
  • $\begingroup$ Thanks! Sorry it's been a while since I've used Mathematica and these I've forgotten that such built-in commands are there --- despite I've Googled for so long for such a solution! $\endgroup$ – user32416 Jul 8 '16 at 10:13
  • $\begingroup$ @Szabolcs #[#2]& is Compose but it won't work with ##2. $\endgroup$ – Kuba Jul 8 '16 at 10:14
5
$\begingroup$

Two possible ways:

listfun = {Sin, Cos, Tan};

Through[listfun[Pi]]
(* {0, -1, 0} *)

#[Pi] & /@ listfun
(* {0, -1, 0} *)
$\endgroup$

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