Clojure – contains?

Clojure contains?

In this guide, we will discuss 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

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply