exercism / clojure

Exercism exercises in Clojure.

Home Page:https://exercism.org/tracks/clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clojure "Accumulate" Tests Return Errors but My Solution Works for 4 of 5 Cases

SSShupe opened this issue · comments

My solution for the "Accumulate" exercise works on four of the five test collections locally (all but the "recursive" collection), but throws an error when I run the test suite. The solution is a straightforward loop-recur (below). The error is

ERROR in (empty-accumulation) (RT.java:667)
expected: (= [] (accumulate/accumulate square []))
  actual: java.lang.UnsupportedOperationException: count not supported on this type: accumulate_test$square

Am I missing something? I'm an amateur coder so that's entirely possible.

I should add that in general I think Exercism is amazing.

(defn accumulate [collection operation]
  (loop [new-c []
         old-c collection]
    (if (= (count old-c) 0)
      new-c
      (recur (conj new-c (operation (first old-c))) (rest old-c)))))

@SSShupe All you need to do is switch the order of the args:

(defn accumulate [operation collection]
. . .