I am a newcomer to Clojure and one of the challenges suggested is a user-implementation of the Filter function.
So I came up with this
(defn filterr
"Filter implementation"
[condition coll]
(if-not (empty? coll)
(if (condition (first coll))
(cons (first coll) (filterr condition (rest coll)))
(filterr (condition (rest coll))))))
(defn -main
"Main" []
(t/is (=
(filterr #(> % 2) [1 2 3 4 5 6])
[3 4 5 6])
"Failed basic test"))
However, my test fails with the error
ERROR in () (Numbers.java:229)
Failed basic test
expected: (= (filterr (fn* [p1__42#] (> p1__42# 2)) [1 2 3 4 5 6])
[3 4 5 6])
It seems like the function isn't being evaluated fully.
I don't see what I'm doing wrong, and would really appreciate some help on the matter.