clojure Clojure destructuring Overview


Destructuring allows you to extract data from various objects into distinct variables. In each example below, each variable is assigned to its own string (a="a", b="b", &c.)

TypeExampleValue of data / comment
vec(let [[a b c] data ...)["a" "b" "c"]
nested vec(let [[[a b] [c d]] data ...)[["a" "b"] ["c" "d"]]
map(let [{a :a b :b c :c} data ...){:a "a" :b "b" :c "c"}
— alternative:(let [{:keys [a b c]} data ...)When variables are named after the keys.