tonsky / persistent-sorted-set

Fast B-tree based persistent sorted set for Clojure/Script

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get with custom comparator

FiV0 opened this issue · comments

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]

I don’t have an opinion :) Maybe. I always thought about sets as something that has contains? operation, not get

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.