Skip to content

Instantly share code, notes, and snippets.

@Hendekagon
Last active September 27, 2020 11:08
Show Gist options
  • Save Hendekagon/9b985d229186139382a59d4d1e153527 to your computer and use it in GitHub Desktop.
Save Hendekagon/9b985d229186139382a59d4d1e153527 to your computer and use it in GitHub Desktop.
destructuring precedence
(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]
@Hendekagon
Copy link
Author

Hendekagon commented Sep 27, 2020

the order is:

pairs :keys :syms :strs

i.e. pairs - traditional destructuring, keywords, symbols, strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment