Clojure – Maps select-keys

Clojure maps select-keys

In this guide, we will discuss Clojure Maps select-keys. 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.

(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}

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply