Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;;; All Kinds of Destructuring ;;;
(let [foo 1] foo)
; => 1
(let [[foo bar] [1 2 3]] [foo bar])
; => [1 2]
(let [[foo bar & baz] [1 2 3]] [foo bar baz])
; => [1 2 (3)]
(let [{:keys [foo bar]} {:a 1, :b 2,}] [foo bar])
; => [1 2]
(let [h {:a 1, :b 2, :c 3, :d 4}] [(keys h) (vals h)])
; => [(:d :c :b :a) (4 3 2 1)]
;; d is the whole input collection [1 2 3 4]
(let [[a b c :as d] [1 2 3 4]] d)
; => [1 2 3 4]
(let [[a b c :as d] [1 2 3 4]] [a b c])
; => [1 2 3]
;; thanks, chouser.
(let [[a :as [b :as [c & [d]]]] [1 2]] [a b c d])
; => [1 1 1 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.