{"id":380155,"date":"2024-06-27T15:01:19","date_gmt":"2024-06-27T15:01:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=380155"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=380155","title":{"rendered":"<span>Clojure: cond-&gt;, deep-merge, remove-nils \u0438 \u0444\u043e\u0440\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0433\u0438\u0434\u0440\u0430\u0442\u0430\u0446\u0438\u0438\/\u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 map \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0438 \u0442\u043e, \u043a\u0430\u043a \u043e\u043d\u0438 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0412\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b \u044d\u0442\u043e\u0442 <a href=\"https:\/\/www.youtube.com\/watch?v=9fhnJpCgtUw\"><u>\u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u043e\u043a\u043b\u0430\u0434<\/u><\/a> \u0438 \u0435\u0433\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b \u0432\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u0438\u0434\u0440\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code>(def heavy-ship-data   {:ship-class \"Heavy\"    :name  \"Thunder\"    :main-systems {:engine {:type \"Ion\"}}})  (def light-ship-data   {:ship-class \"Light\"    :name  \"Lightning\"    :main-systems {:engine {:type \"Flux\"}}})<\/code><\/pre>\n<p>\u0421 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0433\u0438\u0434\u0440\u0430\u0442\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u043c\u0430\u043a\u0440\u043e\u0441 <code>cond-><\/code>:<\/p>\n<pre><code>(defn ready-ship-cond->   [{class :ship-class :as ship-data     {{engine-type :type} :engine} :main-systems}]   (cond-> ship-data     (= class \"Heavy\")      (assoc-in [:main-systems :shield :type]                                      \"Heavy shield\")     (= engine-type \"Flux\") (assoc-in [:main-systems :engine :fuel]                                      \"Fusion cells\")     (= engine-type \"Flux\") (assoc-in [:name] \"Fluxmaster\")     true                   (assoc-in [:main-systems :engine :upgrade]                                      \"Neutron spoils\")     true                   (assoc-in [:main-systems :turret]                                      {:type \"Auto plasma incinerator\"})))<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0438\u043d\u0443\u0441\u043e\u0432. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430 \u0444\u043e\u0440\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0443\u0442\u0435\u0439 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0430\u0441\u0442\u044c \u043f\u0443\u0442\u0438 \u043e\u0431\u0449\u0430\u044f.<\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 <code>assoc-in<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 map.<\/p>\n<pre><code>(ready-ship-cond-> heavy-ship-data)  => {:ship-class \"Heavy\",  :name \"Thunder\",  :main-systems  {:engine {:type \"Ion\", :upgrade \"Neutron spoils\"},   :shield {:type \"Heavy shield\"},   :turret {:type \"Auto plasma incinerator\"}}}  (ready-ship-cond-> light-ship-data)  => {:ship-class \"Light\",  :name \"Fluxmaster\",  :main-systems  {:engine   {:type \"Flux\", :fuel \"Fusion cells\", :upgrade \"Neutron spoils\"},   :turret {:type \"Auto plasma incinerator\"}}}<\/code><\/pre>\n<p>\u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0445\u043e\u0434\u0438\u043b \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>foo-merge<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>(foo-merge    ship-data    {:main-systems {:turret  {:type \"Auto plasma incinerator\"}                    :engine  {:upgrade \"Neutron spoils\"                              :fuel    (when (= engine-type \"Flux\")                                        \"Fusion cells\")}                    :shield  {:type (when (= class \"Heavy\")                                     \"Heavy shield\")}}     :name (when (= engine-type \"Flux\") \"Fluxmaster\")})<\/code><\/pre>\n<p>\u041b\u0438\u0447\u043d\u043e \u044f \u043d\u0430\u0445\u043e\u0436\u0443 \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c. \u041c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043e\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u0443\u0442\u0435\u0439, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u0432\u0432\u043e\u0434 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u043e\u0440\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f <code>foo-merge<\/code> \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>deep-merge<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 map:<\/p>\n<pre><code>(defn deep-merge   [&amp; maps]   (if (every? map? maps) (apply merge-with deep-merge maps) (last maps)))<\/code><\/pre>\n<p>\u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <code>cond-><\/code> \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code>(defn remove-nils   [m]   (clojure.walk\/postwalk    (fn [x]      (if (map? x)        (->> (keep (fn [[k v]] (when (nil? v) k)) x)             (apply dissoc x))        x))    m))<\/code><\/pre>\n<p>\u041c\u044b \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <code>deep-merge-no-nils<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>(defn deep-merge-no-nils   [&amp; maps]   (apply deep-merge (remove-nils maps)))<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u043d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0433\u0438\u0434\u0440\u0430\u0442\u043e\u0440\u0430 ready-ship:<\/p>\n<pre><code>(defn ready-ship-deep-merge-no-nils   [{class :ship-class :as ship-data     {{engine-type :type} :engine} :main-systems}]   (deep-merge-no-nils    ship-data    {:main-systems {:turret  {:type \"Auto plasma incinerator\"}                    :engine {:upgrade \"Neutron spoils\"                             :fuel    (when (= engine-type \"Flux\")                                        \"Fusion cells\")}                    :shield {:type (when (= class \"Heavy\")                                     \"Heavy shield\")}}     :name (when (= engine-type \"Flux\") \"Fluxmaster\")}))<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u0430\u043a, \u043a\u0430\u043a \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 map \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 <code>:shield {}<\/code>:<\/p>\n<pre><code>(= (ready-ship-cond->             heavy-ship-data)    (ready-ship-deep-merge-no-nils heavy-ship-data))  => true  (= (ready-ship-cond->             light-ship-data)    (ready-ship-deep-merge-no-nils light-ship-data))  => false  (clojure.data\/diff  (ready-ship-cond->             light-ship-data)  (ready-ship-deep-merge-no-nils light-ship-data))  => (nil  {:main-systems {:shield {}}}  {:main-systems   {:turret {:type \"Auto plasma incinerator\"},    :engine    {:type \"Flux\", :fuel \"Fusion cells\", :upgrade \"Neutron spoils\"}},   :name \"Fluxmaster\",   :ship-class \"Light\"})<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u044f\u0441\u043d\u0438\u043c, \u043a\u0430\u043a\u043e\u0432\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c <code>ready-ship-deep-merge-no-nils<\/code> \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 <code>ready-ship-cond-><\/code>.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/github.com\/hugoduncan\/criterium\"><u>criterium<\/u><\/a> \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0437\u0430\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 clojure:<\/p>\n<pre><code>(require '[criterium.core :as c])  (c\/bench (ready-ship-cond-> heavy-ship-data))  => ... Execution time mean : 738.743093 ns ...  (c\/bench (ready-ship-deep-merge-no-nils heavy-ship-data))  => ... Execution time mean : 16.707967 \u00b5s ...<\/code><\/pre>\n<p>\u041e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e <code>deep-merge<\/code> \u0438 <code>clojure.walk\/postwalk<\/code> \u0441\u0442\u043e\u044f\u0442 \u043d\u0435\u0434\u0435\u0448\u0435\u0432\u043e, \u0438 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>ready-ship-deep-merge-no-nils<\/code> \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0432 22 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>ready-ship-cond-><\/code>.<\/p>\n<p>\u0412\u043e\u0442 \u043c\u044b \u0438 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443. \u041a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u0442\u0430\u043a \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043b\u0443\u0447\u0448\u0435\u0435 \u0438\u0437 \u043e\u0431\u0435\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u041c\u0430\u043a\u0440\u043e\u0441\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u041a\u0430\u043a \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f map \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>cond-><\/code> \u0438 <code>assoc-in<\/code>? \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u043f\u0443\u0442\u0438 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 (\u043b\u0438\u0441\u0442\u043e\u0432\u043e\u043c\u0443) \u0443\u0437\u043b\u0443 \u0432 \u043d\u0430\u0448\u0435\u0439 map:<\/p>\n<pre><code>(defn all-paths [m]   (letfn [(all-paths [m path]             (lazy-seq              (when-let [[[k v] &amp; xs] (seq m)]                (cond (and (map? v) (not-empty v))                      (into (all-paths v (conj path k))                            (all-paths xs path))                      :else                      (cons [(conj path k) v]                            (all-paths xs path))))))]     (all-paths m [])))<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u043f\u0443\u0442\u044c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043b\u0438\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 map.<\/p>\n<pre><code>(all-paths {:ship-class \"Heavy\"               :name  \"Thunder\"               :main-systems {:engine {:type \"Ion\"}                              :shield {:type \"Phase\"}}}  => ([[:ship-class] \"Heavy\"]    [[:name] \"Thunder\"]    [[:main-systems :shield :type] \"Phase\"]    [[:main-systems :engine :type] \"Ion\"])<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a let-\u0431\u0438\u043d\u0434\u0438\u043d\u0433\u043e\u0432 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 <code>let<\/code> \u0438 <code>cond-><\/code>:<\/p>\n<pre><code>(defmacro cond-merge [m1 m2]   (assert (map? m2))   (let [path-value-pairs (all-paths m2)         symbol-pairs     (map (fn [pair] [(gensym) pair]) path-value-pairs)         let-bindings     (mapcat (fn [[s [_ v]]] [s v]) symbol-pairs)         conditions       (mapcat (fn [[s [path _]]]                                    [`(not (nil? ~s)) `(assoc-in ~path ~s)])                                  symbol-pairs)]     `(let [~@let-bindings]        (cond-> ~m1          ~@conditions))))<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0449\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u044d\u0442\u043e\u043c \u043c\u0430\u043a\u0440\u043e\u0441\u0435, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>macroexpand-1<\/code>:<\/p>\n<pre><code>(macroexpand-1 '(cond-merge {:a 1} {:b (when true 3) :c false }))  (clojure.core\/let     [G__26452 (when true 3) G__26453 false]   (clojure.core\/cond->       {:a 1}     (clojure.core\/not (clojure.core\/nil? G__26452))     (clojure.core\/assoc-in [:b] G__26452)     (clojure.core\/not (clojure.core\/nil? G__26453))     (clojure.core\/assoc-in [:c] G__26453)))<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>m1<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0440\u0430\u0432\u043d\u043e <code>nil<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code>(defn ready-ship-cond-merge   [{class :ship-class :as ship-data     {{engine-type :type} :engine} :main-systems}]   (cond-merge    ship-data    {:main-systems {:turret  {:type \"Auto plasma incinerator\"}                    :engine  {:upgrade \"Neutron spoils\"                              :fuel    (when (= engine-type \"Flux\")                                         \"Fusion cells\")}                    :shield  {:type (when (= class \"Heavy\")                                      \"Heavy shield\")}}     :name (when (= engine-type \"Flux\") \"Fluxmaster\")}))<\/code><\/pre>\n<p>\u041c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>ready-ship-cond-merge<\/code> \u0434\u0430\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u0430\u043a \u0438 <code>ready-ship-cond-><\/code>:<\/p>\n<pre><code>(= (ready-ship-cond->             heavy-ship-data)    (ready-ship-cond-merge    heavy-ship-data))  => true  (= (ready-ship-cond->             light-ship-data)    (ready-ship-cond-merge    light-ship-data))  => true<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0443\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0435\u0439 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438!<\/p>\n<pre><code>(c\/bench (ready-ship-cond-merge    heavy-ship-data))  => ... Execution time mean : 775.762294 ns ...<\/code><\/pre>\n<p>\u0425\u043e\u0442\u044f \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u0430\u043a\u0440\u043e\u0441 <code>cond-merge<\/code> \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\/\u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u043e \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 map\u2019\u044b. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043d\u0435 \u043a \u0438\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>:b<\/code> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>:e<\/code> 3. \u042d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>assoc-in<\/code>, \u043d\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c deep-merge.<\/p>\n<pre><code>(cond-merge {:a 1              :b {:e 3}}             {:b (when true {:c 1 :d 2})              :c false})  => {:a 1  :b {:c 1 :d 2}  :c false}<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<pre><code>(cond-merge {:a 1              :b {:e 3}}             {:b {:c (when true 1)                  :d (when true 2)}              :c false})  => {:a 1  :b {:e 3      :c 1      :d 2}  :c false}<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0444\u043e\u0440\u043c\u0443 \u043d\u0430\u0448\u0438\u0445 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u044d\u0440\u0433\u043e\u043d\u043e\u043c\u0438\u043a\u0438 \u0431\u0435\u0437 \u0443\u0449\u0435\u0440\u0431\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0443\u0437\u043d\u0430\u043b\u0438, \u0447\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p><em>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 <\/em><a href=\"https:\/\/otus.pw\/vNS3\/\"><em>\u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u0430 &#171;Clojure Developer&#187;.<\/em><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/825050\/\"> https:\/\/habr.com\/ru\/articles\/825050\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0433\u0438\u0434\u0440\u0430\u0442\u0430\u0446\u0438\u0438\/\u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 map \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0438 \u0442\u043e, \u043a\u0430\u043a \u043e\u043d\u0438 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0412\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b \u044d\u0442\u043e\u0442 <a href=\"https:\/\/www.youtube.com\/watch?v=9fhnJpCgtUw\"><u>\u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u043e\u043a\u043b\u0430\u0434<\/u><\/a> \u0438 \u0435\u0433\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b \u0432\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u0438\u0434\u0440\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code>(def heavy-ship-data   {:ship-class \"Heavy\"    :name  \"Thunder\"    :main-systems {:engine {:type \"Ion\"}}})  (def light-ship-data   {:ship-class \"Light\"    :name  \"Lightning\"    :main-systems {:engine {:type \"Flux\"}}})<\/code><\/pre>\n<p>\u0421 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0433\u0438\u0434\u0440\u0430\u0442\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u043c\u0430\u043a\u0440\u043e\u0441 <code>cond-><\/code>:<\/p>\n<pre><code>(defn ready-ship-cond->   [{class :ship-class :as ship-data     {{engine-type :type} :engine} :main-systems}]   (cond-> ship-data     (= class \"Heavy\")      (assoc-in [:main-systems :shield :type]                                      \"Heavy shield\")     (= engine-type \"Flux\") (assoc-in [:main-systems :engine :fuel]                                      \"Fusion cells\")     (= engine-type \"Flux\") (assoc-in [:name] \"Fluxmaster\")     true                   (assoc-in [:main-systems :engine :upgrade]                                      \"Neutron spoils\")     true                   (assoc-in [:main-systems :turret]                                      {:type \"Auto plasma incinerator\"})))<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0438\u043d\u0443\u0441\u043e\u0432. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430 \u0444\u043e\u0440\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0443\u0442\u0435\u0439 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0430\u0441\u0442\u044c \u043f\u0443\u0442\u0438 \u043e\u0431\u0449\u0430\u044f.<\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 <code>assoc-in<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 map.<\/p>\n<pre><code>(ready-ship-cond-> heavy-ship-data)  => {:ship-class \"Heavy\",  :name \"Thunder\",  :main-systems  {:engine {:type \"Ion\", :upgrade \"Neutron spoils\"},   :shield {:type \"Heavy shield\"},   :turret {:type \"Auto plasma incinerator\"}}}  (ready-ship-cond-> light-ship-data)  => {:ship-class \"Light\",  :name \"Fluxmaster\",  :main-systems  {:engine   {:type \"Flux\", :fuel \"Fusion cells\", :upgrade \"Neutron spoils\"},   :turret {:type \"Auto plasma incinerator\"}}}<\/code><\/pre>\n<p>\u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0445\u043e\u0434\u0438\u043b \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>foo-merge<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>(foo-merge    ship-data    {:main-systems {:turret  {:type \"Auto plasma incinerator\"}                    :engine  {:upgrade \"Neutron spoils\"                              :fuel    (when (= engine-type \"Flux\")                                        \"Fusion cells\")}                    :shield  {:type (when (= class \"Heavy\")                                     \"Heavy shield\")}}     :name (when (= engine-type \"Flux\") \"Fluxmaster\")})<\/code><\/pre>\n<p>\u041b\u0438\u0447\u043d\u043e \u044f \u043d\u0430\u0445\u043e\u0436\u0443 \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c. \u041c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043e\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u0443\u0442\u0435\u0439, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u0432\u0432\u043e\u0434 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u043e\u0440\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f <code>foo-merge<\/code> \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>deep-merge<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 map:<\/p>\n<pre><code>(defn deep-merge   [&amp; maps]   (if (every? map? maps) (apply merge-with deep-merge maps) (last maps)))<\/code><\/pre>\n<p>\u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <code>cond-><\/code> \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code>(defn remove-nils   [m]   (clojure.walk\/postwalk    (fn [x]      (if (map? x)        (->> (keep (fn [[k v]] (when (nil? v) k)) x)             (apply dissoc x))        x))    m))<\/code><\/pre>\n<p>\u041c\u044b \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <code>deep-merge-no-nils<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>(defn deep-merge-no-nils   [&amp; maps]   (apply deep-merge (remove-nils maps)))<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u043d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0433\u0438\u0434\u0440\u0430\u0442\u043e\u0440\u0430 ready-ship:<\/p>\n<pre><code>(defn ready-ship-deep-merge-no-nils   [{class :ship-class :as ship-data     {{engine-type :type} :engine} :main-systems}]   (deep-merge-no-nils    ship-data    {:main-systems {:turret  {:type \"Auto plasma incinerator\"}                    :engine {:upgrade \"Neutron spoils\"                             :fuel    (when (= engine-type \"Flux\")                                        \"Fusion cells\")}                    :shield {:type (when (= class \"Heavy\")                                     \"Heavy shield\")}}     :name (when (= engine-type \"Flux\") \"Fluxmaster\")}))<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u0430\u043a, \u043a\u0430\u043a \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 map \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 <code>:shield {}<\/code>:<\/p>\n<pre><code>(= (ready-ship-cond->             heavy-ship-data)    (ready-ship-deep-merge-no-nils heavy-ship-data))  => true  (= (ready-ship-cond->             light-ship-data)    (ready-ship-deep-merge-no-nils light-ship-data))  => false  (clojure.data\/diff  (ready-ship-cond->             light-ship-data)  (ready-ship-deep-merge-no-nils light-ship-data))  => (nil  {:main-systems {:shield {}}}  {:main-systems   {:turret {:type \"Auto plasma incinerator\"},    :engine    {:type \"Flux\", :fuel \"Fusion cells\", :upgrade \"Neutron spoils\"}},   :name \"Fluxmaster\",   :ship-class \"Light\"})<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u044f\u0441\u043d\u0438\u043c, \u043a\u0430\u043a\u043e\u0432\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c <code>ready-ship-deep-merge-no-nils<\/code> \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 <code>ready-ship-cond-><\/code>.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/github.com\/hugoduncan\/criterium\"><u>criterium<\/u><\/a> \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0437\u0430\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 clojure:<\/p>\n<pre><code>(require '[criterium.core :as c])  (c\/bench (ready-ship-cond-> heavy-ship-data))  => ... Execution time mean : 738.743093 ns ...  (c\/bench (ready-ship-deep-merge-no-nils heavy-ship-data))  => ... Execution time mean : 16.707967 \u00b5s ...<\/code><\/pre>\n<p>\u041e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e <code>deep-merge<\/code> \u0438 <code>clojure.walk\/postwalk<\/code> \u0441\u0442\u043e\u044f\u0442 \u043d\u0435\u0434\u0435\u0448\u0435\u0432\u043e, \u0438 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>ready-ship-deep-merge-no-nils<\/code> \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0432 22 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>ready-ship-cond-><\/code>.<\/p>\n<p>\u0412\u043e\u0442 \u043c\u044b \u0438 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443. \u041a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u0442\u0430\u043a \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043b\u0443\u0447\u0448\u0435\u0435 \u0438\u0437 \u043e\u0431\u0435\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u041c\u0430\u043a\u0440\u043e\u0441\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u041a\u0430\u043a \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f map \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>cond-><\/code> \u0438 <code>assoc-in<\/code>? \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u043f\u0443\u0442\u0438 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 (\u043b\u0438\u0441\u0442\u043e\u0432\u043e\u043c\u0443) \u0443\u0437\u043b\u0443 \u0432 \u043d\u0430\u0448\u0435\u0439 map:<\/p>\n<pre><code>(defn all-paths [m]   (letfn [(all-paths [m path]             (lazy-seq              (when-let [[[k v] &amp; xs] (seq m)]                (cond (and (map? v) (not-empty v))                      (into (all-paths v (conj path k))                            (all-paths xs path))                      :else                      (cons [(conj path k) v]                            (all-paths xs path))))))]     (all-paths m [])))<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u043f\u0443\u0442\u044c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043b\u0438\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 map.<\/p>\n<pre><code>(all-paths {:ship-class \"Heavy\"               :name  \"Thunder\"               :main-systems {:engine {:type \"Ion\"}                              :shield {:type \"Phase\"}}}  => ([[:ship-class] \"Heavy\"]    [[:name] \"Thunder\"]    [[:main-systems :shield :type] \"Phase\"]    [[:main-systems :engine :type] \"Ion\"])<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a let-\u0431\u0438\u043d\u0434\u0438\u043d\u0433\u043e\u0432 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 <code>let<\/code> \u0438 <code>cond-><\/code>:<\/p>\n<pre><code>(defmacro cond-merge [m1 m2]   (assert (map? m2))   (let [path-value-pairs (all-paths m2)         symbol-pairs     (map (fn [pair] [(gensym) pair]) path-value-pairs)         let-bindings     (mapcat (fn [[s [_ v]]] [s v]) symbol-pairs)         conditions       (mapcat (fn [[s [path _]]]                                    [`(not (nil? ~s)) `(assoc-in ~path ~s)])                                  symbol-pairs)]     `(let [~@let-bindings]        (cond-> ~m1          ~@conditions))))<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0449\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u044d\u0442\u043e\u043c \u043c\u0430\u043a\u0440\u043e\u0441\u0435, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>macroexpand-1<\/code>:<\/p>\n<pre><code>(macroexpand-1 '(cond-merge {:a 1} {:b (when true 3) :c false }))  (clojure.core\/let     [G__26452 (when true 3) G__26453 false]   (clojure.core\/cond->       {:a 1}     (clojure.core\/not (clojure.core\/nil? G__26452))     (clojure.core\/assoc-in [:b] G__26452)     (clojure.core\/not (clojure.core\/nil? G__26453))     (clojure.core\/assoc-in [:c] G__26453)))<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>m1<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0440\u0430\u0432\u043d\u043e <code>nil<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code>(defn ready-ship-cond-merge   [{class :ship-class :as ship-data     {{engine-type :type} :engine} :main-systems}]   (cond-merge    ship-data    {:main-systems {:turret  {:type \"Auto plasma incinerator\"}                    :engine  {:upgrade \"Neutron spoils\"                              :fuel    (when (= engine-type \"Flux\")                                         \"Fusion cells\")}                    :shield  {:type (when (= class \"Heavy\")                                      \"Heavy shield\")}}     :name (when (= engine-type \"Flux\") \"Fluxmaster\")}))<\/code><\/pre>\n<p>\u041c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>ready-ship-cond-merge<\/code> \u0434\u0430\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u0430\u043a \u0438 <code>ready-ship-cond-><\/code>:<\/p>\n<pre><code>(= (ready-ship-cond->             heavy-ship-data)    (ready-ship-cond-merge    heavy-ship-data))  => true  (= (ready-ship-cond->             light-ship-data)    (ready-ship-cond-merge    light-ship-data))  => true<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0443\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0435\u0439 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438!<\/p>\n<pre><code>(c\/bench (ready-ship-cond-merge    heavy-ship-data))  => ... Execution time mean : 775.762294 ns ...<\/code><\/pre>\n<p>\u0425\u043e\u0442\u044f \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u0430\u043a\u0440\u043e\u0441 <code>cond-merge<\/code> \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\/\u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u043e \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 map\u2019\u044b. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043d\u0435 \u043a \u0438\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>:b<\/code> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>:e<\/code> 3. \u042d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>assoc-in<\/code>, \u043d\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c deep-merge.<\/p>\n<pre><code>(cond-merge {:a 1              :b {:e 3}}             {:b (when true {:c 1 :d 2})              :c false})  => {:a 1  :b {:c 1 :d 2}  :c false}<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<pre><code>(cond-merge {:a 1              :b {:e 3}}             {:b {:c (when true 1)                  :d (when true 2)}              :c false})  => {:a 1  :b {:e 3      :c 1      :d 2}  :c false}<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-380155","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380155"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380155\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}