Add map destructuring.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
(def test-address
|
||||
{:street-address "123 Test Lane"
|
||||
:city "Testerville"
|
||||
:state "TX"})
|
||||
|
||||
(meditations
|
||||
"Destructuring is an arbiter: it breaks up arguments"
|
||||
(= __ ((fn [[a b]] (str b a))
|
||||
@@ -21,4 +26,17 @@
|
||||
(let [[first-name last-name :as full-name] ["Steven" "Hawking"]]
|
||||
__))
|
||||
|
||||
"Break up maps by key"
|
||||
(= "123 Test Lane, Testerville, TX"
|
||||
(let [{street-address :street-address, city :city, state :state} test-address]
|
||||
__))
|
||||
|
||||
"Or more succinctly"
|
||||
(= "123 Test Lane, Testerville, TX"
|
||||
(let [{:keys [street-address __ __]} test-address]
|
||||
__))
|
||||
|
||||
"All together now!"
|
||||
(= "Test Testerson, 123 Test Lane, Testerville, TX"
|
||||
(___ ["Test" "Testerson"] test-address))
|
||||
)
|
||||
|
Reference in New Issue
Block a user