Clojure-maps-merge

提供:Dev Guides
2020年6月22日 (月) 22:43時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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}