dimanche 26 octobre 2014

And predicate filtering clojure


Vote count:

0




I have function that take any amount of predicates and filters the seq for each one of them like this



(defn andp [& fns]
(fn [& args]
(every? #(apply % args) fns)))

(defn pred-and
([] "what to return")
([x] x)
([x y] (andp x y))
([x y & more]
(reduce pred-and (pred-and x y) more)
)
)


this works as expected for 1 2 or more params like this:




  1. (filter (pred-and pos? odd?) [1 2 -4 0 6 7 -3]) => [1 7]




  2. (filter (pred-and number? integer? pos? even?) [1 0 -2 :a 7 "a" 2]) => [2]




the problem is when I pass no parameters it should return the original sequence how to do that?


(filter (pred-and) [1 0 -2]) => [1 0 -2]



asked 44 secs ago







And predicate filtering clojure

Aucun commentaire:

Enregistrer un commentaire