Merge 4e5533041d into a4556887b4
This commit is contained in:
commit
a6cb270009
1 changed files with 10 additions and 0 deletions
|
|
@ -44,6 +44,9 @@
|
||||||
"Create a new map by merging"
|
"Create a new map by merging"
|
||||||
(= {:a 1 :b 2 __ __} (merge {:a 1 :b 2} {:c 3}))
|
(= {:a 1 :b 2 __ __} (merge {:a 1 :b 2} {:c 3}))
|
||||||
|
|
||||||
|
"Specify how to handle entries with same keys when merging"
|
||||||
|
(= {:a 1 :b __ :c 3} (merge-with + {:a 1 :b 1} {:b 1 :c 3}))
|
||||||
|
|
||||||
"Often you will need to get the keys, but the order is undependable"
|
"Often you will need to get the keys, but the order is undependable"
|
||||||
(= (list __ __ __)
|
(= (list __ __ __)
|
||||||
(sort (keys { 2014 "Sochi" 2018 "PyeongChang" 2010 "Vancouver"})))
|
(sort (keys { 2014 "Sochi" 2018 "PyeongChang" 2010 "Vancouver"})))
|
||||||
|
|
@ -51,3 +54,10 @@
|
||||||
"You can get the values in a similar way"
|
"You can get the values in a similar way"
|
||||||
(= (list __ __ __)
|
(= (list __ __ __)
|
||||||
(sort (vals {2010 "Vancouver" 2014 "Sochi" 2018 "PyeongChang"}))))
|
(sort (vals {2010 "Vancouver" 2014 "Sochi" 2018 "PyeongChang"}))))
|
||||||
|
|
||||||
|
"You can even iterate over the map entries as a seq"
|
||||||
|
(= {:a __ :b __}
|
||||||
|
(into {}
|
||||||
|
(map
|
||||||
|
(fn[[k v]] [k (inc v)])
|
||||||
|
{:a 1 :b 2})))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue