Clojure – Sequences distinct

Clojure sequences distinct

In this guide, we will discuss Clojure Sequences distinct. Used to only ensure that distinct elements are added to the sequence.

Syntax

Following is the syntax.

(distinct seq1)

Parameters − ‘seq1’ is the sequence list of elements.

Return Value − The sequence of elements wherein only distinct elements are returned.

Example

Following is an example of distinct in Clojure.

(ns clojure.examples.example
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (def seq1 (distinct (seq [1 1 2 2])))
   (println seq1))
(Example)

Output

The above program produces the following output.

(1 2)

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply