Odd exception on lazy sequence

33 views
Skip to first unread message

KJO

unread,
Feb 14, 2020, 7:12:53 AM2/14/20
to Clojure
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))))

KJO

unread,
Feb 14, 2020, 11:45:02 AM2/14/20
to Clojure
OK. I got some super guidance from p-himik on the Slack channel (Thank you!).

Essentially there was a TreeSet in one of the sets to be conj'ed and that was causing the exception. Apparently, it's not a trivial matter to conj tree-sets :-).
Reply all
Reply to author
Forward
0 new messages