open:destructuring

Destructuring

Destructuring allows us to conveniently bind elements of collections to symbols

(def s [1 2 3])
 
;with destructuring
(let [[x y] s]
  (do-stuff x y)) ; (do-stuff 1 2)

(def s [1])
 
;with destructuring
(let [[x y z] s]
  (do-stuff x y z)) ; (do-stuff 1 nil nil)

(def m {:y 3 :x 8 :z -5})
 
;with destructuring
(let [{:keys [x z]} m]
  (do-stuff x z)) ; (do-stuff 8 -5)


  • open/destructuring.txt
  • 마지막으로 수정됨: 2021/11/01 06:50
  • 저자 127.0.0.1