目录

rename-keys

将当前HashMap中的键重命名为新定义的键。

语法 (Syntax)

以下是语法。

(rename-keys hmap keys)

Parameters - 'hmap'是散列键和值的映射。 'keys'是需要在地图中替换的新键列表。

Return Value - 返回带有新键列表的映射。

例子 (Example)

以下是Clojure中重命名密钥的示例。

(ns clojure.examples.example
   (:require [clojure.set :as set])
   (:gen-class))
(defn example []
   (def demokeys (hash-map "z" 1 "b" 2 "a" 3))
   (def demonew (set/rename-keys demokeys {"z" "newz" "b" "newb" "a" "newa"}))
   (println demonew))
(example)

输出 (Output)

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

{newa 3, newb 2, newz 1}
↑回到顶部↑
WIKI教程 @2018