Clojure-maps-merge
提供:Dev Guides
Clojure-マップのマージ
2つのマップエントリを1つの単一のマップエントリにマージします。
構文
構文は次のとおりです。
(merge hmap1 hmap2)
パラメータ-「hmap1」はハッシュキーと値のマップです。 「hmap2」はハッシュキーと値のマップであり、最初のHashMapでマップする必要があります。
戻り値-hasmap1とhasmap2の両方のHashMapを組み合わせて返します。
例
以下は、Clojureでのマージの例です。
(ns clojure.examples.example
(:gen-class))
(defn example []
(def demokeys (hash-map "z" 1 "b" 2 "a" 3))
(def demokeys1 (hash-map "a" 2 "h" 5 "i" 7))
(println (merge-with + demokeys demokeys1)))
(example)
出力
上記のコードは次の出力を生成します。
{z 1, x 4, a 3, i 7, b 2, h 5}