Welcome! Please see the About page for a little more info on how this works.

0 votes
in Collections by
edited by

Is it intended behavior to get this exception :

class clojure.lang.Keyword cannot be cast to class java.util.Map$Entry

on this piece of code :

(def a [["Active" :Transit-RLC "Active"]])

(->> a
             (map drop-last)
             (map reverse))
       conj [])
     (into {}))

changing the transducer to (map (-> [(second %) (first %)]) solves the issue.

1 Answer

+2 votes
selected by
Best answer

Any significance of using transduce before into? This should work:

(->> a
 (into {}
         (map drop-last)
         (map reverse)
         (map vec))))

Note the (map vec) at the end, see https://clojuredocs.org/clojure.core/into#example-5858e2eae4b004d3a355e2c8 on why that is needed. You could also replace (map reverse) witg (map (juxt second first)) which produces vectors so (map vec) won't be needed.