Hi all,
I am trying to implement the function 'group-by' from Clojure.Core
using my current knowledge of Clojure but cannot get pass a
java.lang.Exception.
This is the code so far:
(defn key? [key coll]
(some #{key} (keys coll)))
(defn my-group-by [f coll]
(let [test (fn [m x]
(let [res (f x)]
(if (key? res m)
(conj (m res) x)
(assoc m res (vec x)))))]
(reduce test {} coll)))
Calling 'my-group-by' throws an exception:
(my-group-by (fn [x] (mod x 3)) [0 1 2 3 4 5 6 7 8 9 10])
;; java.lang.Exception: Unable to convert: class java.lang.Integer to
Object[] (repl-1:2)
This is the result that should have been returned if everything was
correct:
{2 (2 5 8), 1 (1 4 7 10), 0 (0 3 6 9)}
So, far I have been unable to find the place in my code where an
Integer is passed incorrectly. Any suggestions are highly
appreciated!
Best regards,
Stefan
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en