Unique collections with fast membership tests: create sets, add/remove items, and use clojure.set for union/intersection/difference.
Sets represent unique elements and excel at membership checks. If you’re coming from Java, think HashSet—but persistent and immutable.
1#{:a :b :c}
2(set [1 1 2 3]) ; => #{1 2 3}
1(def roles #{:admin :billing})
2
3(contains? roles :admin) ; => true
4(roles :admin) ; => :admin ; set-as-function membership
5(roles :guest) ; => nil
1(conj #{1 2} 3) ; => #{1 2 3}
2(disj #{1 2} 2) ; => #{1}
Adding a duplicate changes nothing:
1(conj #{1 2} 2) ; => #{1 2}
clojure.set)1(require '[clojure.set :as set])
2
3(set/union #{1 2} #{2 3}) ; => #{1 2 3}
4(set/intersection #{1 2} #{2 3}) ; => #{2}
5(set/difference #{1 2} #{2 3}) ; => #{1}