Clojure - 查詢 Map



返回鍵對應的 Map 條目。

語法

以下是語法。

(find hmap key)

引數 − ‘hmap’ 是雜湊鍵值對的 Map。 ‘key’ 是需要在 Map 中搜索的鍵。

返回值 − 返回所需鍵對應的鍵值對,否則返回 nil。

示例

以下是 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
clojure_maps.htm
廣告

© . All rights reserved.