目录

merge

将两个映射条目合并为一个映射条目。

语法 (Syntax)

以下是语法。

(merge hmap1 hmap2)

Parameters - 'hmap1'是散列键和值的映射。 'hmap2'是散列键和值的映射,需要与第一个HashMap映射。

Return Value - 返回hasmap1和hasmap2的组合HashMap。

例子 (Example)

以下是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)

输出 (Output)

上面的代码产生以下输出。

{z 1, x 4, a 3, i 7, b 2, h 5}
↑回到顶部↑
WIKI教程 @2018