What is the get() method in Clojure?

What is a set in Clojure?

A set is a data structure that stores data in an unsorted manner. It contains a collection of unique data values.

What is a get method in Clojure?

A get method returns the selected element of a set.

Syntax

(get setofelements element)

Parameter(s)

The get method receives two parameters:

  1. setofelement: the set
  2. element: the element

Return Value

The get method returns an element from the set.

Example

(ns clojure.examples.example
(:gen-class))
(defn gett []
(println (get (set '(4 6 8)) 4))
(println (get (set '(3 2 1)) 1)))
(gett)

Explanation

From the code above:

  • Line 3: We define a function gett.

  • Line 4: We print the element returned using the println. The get method is used to get data value 4 from the set.

  • Line 5: We print the element returned using the println. The get method is used to get data value 1 from the set.

  • Line 6: We call the gett function.

Free Resources