Add map destructuring.

This commit is contained in:
Colin Jones
2010-11-11 18:16:55 -06:00
parent a7f7df6f01
commit 3bba4879db
2 changed files with 27 additions and 2 deletions

View File

@@ -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))
)