For lists and vectors, we can slice the sequence and take any portion we want. How to do similar operations to map objects ?
For example, I have a list of map object,
(def plays [
{:name "Burial", :plays 979, :loved 9}
{:name "Eno", :plays 2333, :loved 15}
{:name "Bill", :plays 979, :loved 9}
{:name "Magma", :plays 2665, :loved 31}])
For each map, I want to slice off plays column, and add rate column with default value, what is the idiomatic way to do this ?
assoc
and dissoc
are your friends in this case:
(map #(-> % (dissoc :plays)
(assoc :rate 10)) plays)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With