redplanetlabs / specter

Clojure(Script)'s missing piece
Apache License 2.0
2.51k stars 102 forks source link

`submap` sub map should maintain properties of parent map #235 #296

Open jeff303 opened 3 years ago

jeff303 commented 3 years ago

TODO: figure out how to handle transients (i.e. submap!)

Adding new SubMap protocol to handle the different implementations of key selection (including one that maintains order to be used for sorted-map)

Adding test to ensure order preserved for a large map

jeff303 commented 3 years ago

I'm not sure how to handle transients here (i.e. submap!).

# for TransientHashMap
(select-keys (transient {:a 1 :b 2 :c 3 :d 4 :e 5 :f 6 :g 7 :h 8 :i 9 :j 10 :k 11 :l 12 :m 13}) [:a :c :e :g :i :k :m])
{:a 1, :c 3, :e 5, :g 7, :i 9, :k 11, :m 13}
# for TransientArrayMap
(select-keys (transient {:a 1 :b 2 :c 3 :d 4 :e 5 :f 6 :g 7}) [:g :f :e :d :c :b :a])
{:g 7, :f 6, :e 5, :d 4, :c 3, :b 2, :a 1}
nathanmarz commented 3 years ago

Couple comments:

nathanmarz commented 3 years ago

Also, transients aren't supported on PersistentTreeMap, so submap! doesn't need any changes.

jeff303 commented 3 years ago

Added the test for the actual comparator (couldn't quickly figure out if/how to make that work in cljs).

Also, transients aren't supported on PersistentTreeMap, so submap! doesn't need any changes

OK, thanks for the confirmation. The starter comment on #235 is what got me looking at it.