Filtering a list in dependence of that list in clojure
Suppose you have the following code to get all primes until a parameter:
(defn my-filt [x z]
(or (not= 0 (mod z x))
(= z x)
)
)
(defn my-filter [y x]
(filter (partial my-filt x) y)
)
(defn primes [end_prime]
(reduce my-filter
(cons (range 2 end_prime) (range 2 end_prime))
)
)
(primes 19)
As you can see i use partial my-filt x, because i need the list x in the my-filt function, because a filter just depends on one parameter. My question is following: Is there a better way of using idiomatic clojure not to use partial in a filter?
from Recent Questions - Stack Overflow https://ift.tt/3oiWFvh
https://ift.tt/eA8V8J
Comments
Post a Comment