diff --git a/resources/koans.clj b/resources/koans.clj index 6ae3398..b302af5 100644 --- a/resources/koans.clj +++ b/resources/koans.clj @@ -80,8 +80,10 @@ "February" 1 "January" :c 3 + 2 2010 2014 2018 - "PyeongChang" "Sochi" "Vancouver"]}] + "PyeongChang" "Sochi" "Vancouver" + 2 3]}] ["07_functions" {"__" [81 20 diff --git a/src/koans/06_maps.clj b/src/koans/06_maps.clj index d4af87c..6b66099 100644 --- a/src/koans/06_maps.clj +++ b/src/koans/06_maps.clj @@ -44,6 +44,9 @@ "Create a new map by merging" (= {: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" (= (list __ __ __) (sort (keys { 2014 "Sochi" 2018 "PyeongChang" 2010 "Vancouver"}))) @@ -51,3 +54,10 @@ "You can get the values in a similar way" (= (list __ __ __) (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})))