Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clojure, using a list of functions

Tags:

clojure

I would like to define a list of functions to use within juxt, however I am having trouble implementing it.

Heres an example of what I want:

(defn sin [n] (Math/sin n))
(defn cos [n] (Math/cos n))
((juxt sin cos) 4)
>> [-0.7568024953079282 -0.6536436208636119]

Now instead of saying ((juxt sin cos) 4) I would prefer to say ((juxt trig) 4) where (def trig [sin cos]). I have attempted ((apply juxt trig) 4) and a few other things but nothing seems to stick. Thanks!

like image 792
ChrisR Avatar asked Mar 02 '26 09:03

ChrisR


1 Answers

apply seems to work fine:

user=> ((juxt sin cos) 4)
[-0.7568024953079282 -0.6536436208636119]
user=> ((apply juxt trig) 4)
[-0.7568024953079282 -0.6536436208636119]
like image 196
skuro Avatar answered Mar 05 '26 03:03

skuro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!