Clojure Destructuring — :keys, :or & :as | Episode 13
0views
C
CelesteAI
Description
Reaching into data structures one field at a time gets noisy fast. Destructuring pulls values out in one clean, declarative form — no repeated get calls, no temporary bindings, no accessor boilerplate.
In this episode we cover vector destructuring, map destructuring with :keys, defaults with :or, keeping the whole with :as, nested destructuring, and pulling fields directly in function parameters.
Phase 2 finale!
Student code: https://github.com/GoCelesteAI/clojure-for-beginners/tree/main/episode13
Every keystroke is shown on screen with generous pauses so you can follow along at your own pace.
What You'll Learn:
- Vector destructuring — bind by position with [a b c]
- & rest — capture remaining items
- Map destructuring — :keys [name age] binds by name
- :or — default values when a key is missing
- :as — keep the whole value plus extract fields
- Nested destructuring — reach into maps inside maps
- Destructuring in function parameters for clean API boundaries
Timestamps:
0:00 - Intro
0:12 - Preview: pull data apart without accessor noise
0:32 - Start the REPL
0:40 - Vector destructuring
0:54 - Map destructuring with :keys and :or
1:10 - Function parameter destructuring
1:25 - Exit REPL
1:30 - Write destructuring.clj in Neovim
1:51 - Vector section
2:58 - Map section
4:10 - Function parameter section
5:05 - Nested destructuring section
5:56 - :as section
6:54 - Run with :!clj -M %
6:58 - Output explained line by line
7:49 - Review
7:59 - Recap
8:34 - Phase 2 complete — What's next: Episode 14
Key Takeaways:
1. Vector destructuring binds by position. Map destructuring binds by key.
2. :or provides defaults for missing keys — no nil checks needed.
3. :as keeps the original value alongside the extracted fields.
4. Destructure function parameters directly — cleaner than (get args :key) in the body.
Phase 2 complete! Next up, Phase 3 — Functional Core, starting with Episode 14: map, filter, reduce.
Taught by CelesteAI. Like and subscribe for more Clojure tutorials!