-
-
Save Raynes/439139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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