Last active
September 27, 2020 11:08
-
-
Save Hendekagon/9b985d229186139382a59d4d1e153527 to your computer and use it in GitHub Desktop.
destructuring precedence
This file contains 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
(let [{z :x x 'y y "z" :keys [x y z] :syms [x y z] :strs [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil nil 3] | |
(let [{z :x x 'y y "z" :keys [x y z] :syms [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil 2 nil] | |
(let [{z :x x 'y y "z" :keys [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [1 nil nil] | |
(let [{z :x x 'y y "z"} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [2 3 1] | |
(let [{z :x x 'y y "z" :syms [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil 2 nil] | |
(let [{z :x x 'y y "z" :strs [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil nil 3] | |
(let [{z :x x 'y y "z" :keys [x] :syms [y] :strs [z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [1 2 3] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the order is:
pairs :keys :syms :strs
i.e. pairs - traditional destructuring, keywords, symbols, strings