Clojure Sets — Unique Collections & Set Math | Episode 10
0views
C
CelesteAI
Description
Sets guarantee every element is unique. They double as membership functions. And clojure.set gives you real set math — union, intersection, and difference — built right into the standard library.
In this episode we create sets, test membership, add and remove elements, and use clojure.set to compare frontend and backend skill sets. Every operation returns a new set because sets are immutable.
Student code: https://github.com/GoCelesteAI/clojure-for-beginners/tree/main/episode10
Every keystroke is shown on screen with generous pauses so you can follow along at your own pace.
What You'll Learn:
- Set literal syntax with hash-curly-braces
- conj adds elements (duplicates silently ignored)
- disj removes elements
- Sets as membership functions: (colors :blue) returns :blue or nil
- contains? for explicit membership testing
- require clojure.set for set operations
- union, intersection, and difference
- Practical example: comparing frontend vs backend skill sets
Timestamps:
0:00 - Intro
0:12 - Preview: unique, unordered, mathematical
0:32 - Start the REPL
0:40 - Create sets
0:52 - conj and disj
1:05 - Membership testing
1:18 - clojure.set operations
1:49 - Exit REPL
1:54 - Write sets.clj in Neovim
2:14 - Create, conj/disj sections
3:20 - Duplicates, membership sections
4:28 - Set operations with frontend/backend skills
5:57 - Run with :!clj -M %
6:01 - Output explained line by line
6:57 - Review
7:05 - Recap
7:40 - What's next: Episode 11
Key Takeaways:
1. Hash-curly creates a set. Duplicates are silently ignored.
2. Sets are functions — call them with an element to test membership.
3. conj adds, disj removes. Same verbs as vectors and lists.
4. clojure.set provides union, intersection, and difference.
Next up — Episode 11: The Seq Abstraction.
Taught by CelesteAI. Like and subscribe for more Clojure tutorials!