In this guide, we will discuss Clojure map-invert. Inverts the maps so that the values become the keys and vice versa.
Syntax
Following is the syntax.
(map-invert hmap)
Parameters − ‘hmap’ is the map of hash keys and values.
Return Value − Returns a map with the values inverted to the keys and the keys inverted to values.
Example
Following is an example of map-invert 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/map-invert demokeys)) (println demonew)) (example)
Output
The above code produces the following output.
{1 z, 3 a, 2 b}
Next Topic : Click Here
Pingback: Clojure - Maps rename-keys | Adglob Infosystem Pvt Ltd
Pingback: Clojure - Maps | Adglob Infosystem Pvt Ltd