I'm stumped on this. I have a function that returns a lazy sequence (let's call
it lzs - it's produced by another function, and for this exercise I def'd it
in the REPL from `*1'). It's a sequence of maps.
When I apply a merge-with operation to the lazy sequence. I get the following
error.
class clojure.lang.PersistentHashSet cannot be cast to class
java.lang.Comparable (clojure.lang.PersistentHashSet is in unnamed
module of loader 'app'; java.lang.Comparable is in module java.base
of loader 'bootstrap'
If I apply the same operation on a `doall' of the sequence, I also get the error.
However, if I fully realize the sequence in the REPL and feed it into the
merge operation, I don't get the error. There's really no magic in the merge-with
operation, it just conj's some sets.
Any ideas?
The relevant code is below:
;; FAILS
(apply
merge-with
px-tran-netter-ex
lzs)
;; FAILS
(apply
merge-with
px-tran-netter-ex
(doall lzs))
;; NO PROBLEM HERE with lzs realized and fed back in
(apply
merge-with
px-tran-netter-ex
'({:fund {:src-ax-id #{nil :ax-m01}}}
{:fund {:src-ax-id #{:ax-m01}}}
{:fund {:src-ax-id nil}}
{:fund {:src-ax-id :ax-m01}}
{:fund {:src-ax-id #{:ax-m01}}}
{:fund {:src-ax-id #{nil :ax-m01}}}
{:fund {:src-ax-id #{:ax-m01}}}
{:fund {:src-ax-id nil}}
{:fund {:src-ax-id :ax-m01}}
{:fund {:src-ax-id #{:ax-m01}}}))
The px-tran-netter-ex is
(defn px-tran-netter-ex
[ov nv]
(if (nil? ov)
nv
(update
ov
:src-ax-id
(fn px-tran-set-merger
[lv rv]
(if (some? rv)
(conj
(if (set? lv)
lv
(if (some? lv)
#{lv}
#{}))
rv)
lv))
(:src-ax-id nv))))