Skip to content

Instantly share code, notes, and snippets.

@jeluard
Last active July 17, 2018 06:01
Show Gist options
  • Save jeluard/074d0298f5f4517e62401f445c5f84dd to your computer and use it in GitHub Desktop.
Save jeluard/074d0298f5f4517e62401f445c5f84dd to your computer and use it in GitHub Desktop.

Sequential data structure

Extract seq elements by index Elements can be ignored with _ :as symbol denotes the whole sequence

Examples

[[a _ c :as all] [1 2 3 4 5]]
;; a = 1
;; c = 3
;; all = [1 2 3 4 5]

Associative data structure

Extract map values by keys {a :a} Optional values via #{a 5} No namespaced keyword support, no short syntax

Examples

[{a :a a :b #{c 4} :c :all all} {:a 1 :b 2 :d 3}]
;; a = 1
;; b = 2
;; c = 4
;; all = {:a 1 :b 2 :d 3}

Nesting

Both structure type destrucuring can be combined

[{[a1 _ a3] :a {d :d #{f 7} :f #{[_ g2] 8}} :b [_ e2] :e :all all}
 {:a [1 2 3] :b {:d 4 :e [5 6] :g [9 10]}}]
;; a1 = 1
;; a3 = 3
;; d = 4
;; e2 = 5
;; f = 7
;; g2 = 10
;; all = {:a [1 2 3] :b {:d 4 :e [5 6] :g [9 10]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment