Clojure - contains?



Finds out whether the set contains a certain element or not.

Syntax

Following is the syntax.

(contains? setofelements searchelement)

Parameters − ‘setofelements’ is the set of elements. ‘Searchelement’ is the element which needs to be searched for in the list.

Return Value − Returns true if the element exists in the set or false if it dosen’t.

Example

Following is an example of contains? in Clojure.

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (println (contains? (set '(3 2 1)) 2))
   (println (contains? (set '(3 2 1)) 5)))
(example)

Output

The above code produces the following output.

true
false
clojure_sets.htm
Advertisements