Clojure - Maps rename-keys
Renames keys in the current HashMap to the newly defined ones.
Syntax
Following is the syntax.
(rename-keys hmap keys)
Parameters − hmap is the map of hash keys and values. keys is the new list of keys which need to be replaced in the map.
Return Value − Returns a map with a new list of keys.
Example
Following is an example of rename-keys in 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
The above code produces the following output.
{newa 3, newb 2, newz 1}
clojure_maps.htm
Advertisements