Clojure-maps-renamekeys
提供:Dev Guides
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}