Clojure - Maps select-keys


Advertisements


Returns a map containing only those entries in map whose key is in keys.

Syntax

Following is the syntax.

(select-keys hmap keys)

Parameters − ‘hmap’ is the map of hash keys and values. ‘keys’ is the list of keys which need to be selected from the HashMap.

Return Value − Returns the keys from the map as per the select clause of keys.

Example

Following is an example of select-keys in Clojure.

Live Demo
(ns clojure.examples.example
   (:gen-class))
(defn example []
   (def demokeys (hash-map "z" 1 "b" 2 "a" 3))
   (println (select-keys demokeys ["z" "a"])))
(example)

Output

The above code produces the following output.

{z 1, a 3}

clojure_maps.htm

Advertisements