get with custom comparator
FiV0 opened this issue · comments
Finn Völkel commented
It would be nice if (get set item)
would return the item actually in the collection not just the key passed in case of a match
(require '[me.tonsky.persistent-sorted-set :as set])
(def data (map vector (range 10) (range 10)))
((into (set/sorted-set-by #(compare (first %1) (first %2))) data) [4 :foo])
;; => [4 :foo]
((into (sorted-set-by #(compare (first %1) (first %2))) data) [4 :foo])
;; => [4 4]
Nikita Prokopov commented
I don’t have an opinion :) Maybe. I always thought about sets as something that has contains?
operation, not get
Finn Völkel commented
Also just realized that for conj
it doesn't have that behavior.
(conj (sorted-set-by #(compare (first %1) (first %2)) [1 2] [2 3]) [1 :foo])
;; => #{[1 2] [2 3]}
so maybe just leave it.