vvvvalvalval / supdate

Clojure's update with superpowers.
https://vvvvalvalval.github.io/supdate/
MIT License
204 stars 4 forks source link

Sets get converted to lists, should they? #8

Open PEZ opened 1 year ago

PEZ commented 1 year ago

I don't know if this is a bug or just out of scope of the library:

(supdate #{} [identity]) => ()

I was expecting:

(supdate #{} [identity]) => #{}

I noticed it when reading this medley PR description: https://github.com/weavejester/medley/issues/63

I tried to solve the example with supdate (mostly to learn how supdate works), and found myself having to restore the set type the orders collection:

(def m {:users [{:id 1 :orders #{{:items [{:price 1} {:price 4} {:price 2}]}}}
                {:id 2 :orders #{}}]}) 
(-> m 
    (supdate {:users [{:orders [{:items [{:price #(str "$" %)}]}]}]})
    (supdate {:users [{:orders set}]}))
=>
{:users [{:id 1 :orders #{{:items [{:price "$1"} {:price "$4"} {:price "$2"}]}}}
         {:id 2 :orders #{}}]}