codecamp

Clojure Maps find

返回键的映射项。

语法

以下是语法。

(find hmap key)

参数 - 'hmap'是哈希键和值的映射。'key'是需要在映射中搜索的键。

返回值 - 返回所需键的键值对,否则返回零。

例子

以下是Clojure 中find的例子。

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (def demokeys (hash-map "z" "1" "b" "2" "a" "3"))
   (println demokeys)
   (println (find demokeys "b"))
   (println (find demokeys "x")))
(example)

输出

上述代码输出以下结果。

{z 1, a 3, b 2}
[b 2]
nil
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定