In this guide, we will discuss Clojure union. Return a set that is the union of the input sets.
Syntax
Following is the syntax.
(union set1 set2)
Parameters − ‘set1’ is the first set of elements. ‘set2’ is the second set of elements.
Return Value − The joined set of elements.
Example
Following is an example of union in Clojure.
(ns clojure.examples.example (:require [clojure.set :as set]) (:gen-class)) (defn example [] (println (set/union #{1 2} #{3 4}))) (example)
Note that in the above example, you have to use the require statement to include the clojure.set class which contains the union method.
Output
The above code produces the following output.
#{1 4 3 2}
Next Topic : Click Here
Pingback: Clojure - disj | Adglob Infosystem Pvt Ltd
Pingback: Clojure - Sets | Adglob Infosystem Pvt Ltd