Clojure - intersection



Return a set that is the intersection of the input sets.

Syntax

Following is the syntax.

(intersection set1 set2)

Parameters − ‘set1’ is the first set of elements. ‘set2’ is the second set of elements.

Return Value − The intersection between the different set of elements.

Example

Following is an example of intersection in Clojure.

(ns clojure.examples.example
   (:require [clojure.set :as set])
   (:gen-class))
(defn example []
   (println (set/intersection #{1 2} #{2 3})))
(example)

Output

The above code produces the following output.

#{2}
clojure_sets.htm
Advertisements