2
$\begingroup$

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$
5
  • 1
    $\begingroup$ Does Through fit your needs? $\endgroup$
    – Kuba
    Commented Jul 8, 2016 at 10:10
  • 6
    $\begingroup$ (83878) $\endgroup$
    – Kuba
    Commented Jul 8, 2016 at 10:11
  • $\begingroup$ @Kuba Is there a builtin for #1[##2]& or similar? $\endgroup$
    – Szabolcs
    Commented Jul 8, 2016 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
    Commented Jul 8, 2016 at 10:13
  • $\begingroup$ @Szabolcs #[#2]& is Compose but it won't work with ##2. $\endgroup$
    – Kuba
    Commented Jul 8, 2016 at 10:14

1 Answer 1

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.