mirror of
https://github.com/status-im/pluto.git
synced 2025-02-24 16:38:16 +00:00
885 B
885 B
title | sidebar_label |
---|---|
Block | Block |
Let block
Destructuring
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 :as 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]}}