In Java, with a java.util.SortedMap<Long,Object>, we can do something like:
sortedMap.headSet(13).clear()
to get rid of all the elements with keys < 13. I don’t see anything similar in clojure.core for clojure’s (sorted-map) (which I think is always a clojure.lang.PersistentTreeMap). The best I’ve come up with is something like this:
(let [clear-up-to 13
sm (sorted-map 1 "aye" 2 "bee" 13 "em" 14 "en")]
clear-keys (take-while #(< % clear-up-to) (keys sm))
(apply dissoc sm clear-keys))
Am I missing something simpler?
Dissoc is the best you can do, but the
take-whilestep should be replaced withsubseqorrsubseq, as appropriate.