Skip to content

Instantly share code, notes, and snippets.

View kul's full-sized avatar
🪲

kul

🪲
  • Bangalore, India
View GitHub Profile
@john2x
john2x / 00_destructuring.md
Last active April 23, 2024 13:18
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

(def src [[{:name "smeagol"}]
[{:name "gollum"}]
[{:tuple "field!"}]])
;; Retrieve some field from a bunch of records:
(??<- [?name]
(src ?m)
(get ?m :name :> ?name))
;;=> (["smeagol"] ["gollum"])