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

+2 votes
in data.priority-map by
edited by

Hi folks!

Just a heads-up that clojure.data.priority-map’s IKVReduce implementation doesn’t support reduced.

The current implementation (v1.2.0, 2024-02-19):

clojure.core.protocols/IKVReduce
(kv-reduce [this f init]
  (if keyfn            
    (reduce-kv (fn [a k v] (reduce (fn [a v] (f a v (item->priority v))) a v))
      init priority->set-of-items)
    (reduce-kv (fn [a k v] (reduce (fn [a v] (f a v k)) a v))
      init priority->set-of-items)))

But the nested reduce means that something like this’d be needed:

(defn- convey-reduced [x] (if (reduced? x) (reduced x) x))

clojure.core.protocols/IKVReduce
(kv-reduce [this f init]
  (if keyfn            
    (reduce-kv (fn [a k v] (reduce (fn [a v] (convey-reduced (f a v (item->priority v))) a v)))
      init priority->set-of-items)
    (reduce-kv (fn [a k v] (reduce (fn [a v] (convey-reduced (f a v k)) a v)))
      init priority->set-of-items)))

Note that the issue affects only (reduce-kv a-priority-map …), not (reduce a-priority-map …).

Thanks, cheers! :-)

Please log in or register to answer this question.

...