Clojure-maps-renamekeys

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

Clojure-マップの名前変更キー

現在のHashMapのキーの名前を新しく定義されたものに変更します。

構文

構文は次のとおりです。

(rename-keys hmap keys)

パラメータ-「hmap」はハッシュキーと値のマップです。 「キー」は、マップ内で置き換える必要があるキーの新しいリストです。

戻り値-キーの新しいリストでマップを返します。

以下は、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)

出力

上記のコードは次の出力を生成します。

{newa 3, newb 2, newz 1}