What is the vals map method in Clojure?
Map in Clojure
A map is a collection that assigns keys to values.
vals map method in Clojure
A vals method is used to get all the values in a map.
Syntax
(vals hmap)
Parameter
The vals method receives one parameter:
hmap: This is the map with hash key and value.
Return value
The vals method returns a list of values in the map.
Example
(ns clojure.examples.example(:gen-class))(defn valss [](def example (hash-map "z" "98" "x" "90" "u" "53"))(println (vals example)))(valss)
Explanation
In the code above:
- In line 3, we define a function
valss. - In line 4, we define a variable
exampleusing the keyworddefand we assign our map to it. - In line 5, we get the values of the map using the
valsmethod and we print them out using theprintlnmethod. - In line 6, we call the
valssfunction.