diff --git a/src/koans/destructuring.clj b/src/koans/destructuring.clj index 9516305..e23779a 100644 --- a/src/koans/destructuring.clj +++ b/src/koans/destructuring.clj @@ -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)) ) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index 0daff8b..4027ee0 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -110,13 +110,20 @@ (interleave (repeat "aka") aliases)) (repeat " ")))) '{:original-parts full-name - :named-parts {:first first-name :last last-name}} ]} + :named-parts {:first first-name :last last-name}} + '(str street-address ", " city ", " state) + 'city 'state + '(str street-address ", " city ", " state)] + "___" ['(fn [[fname lname] + {:keys [street-address city state]}] + (str fname " " lname ", " + street-address ", " city ", " state)) + ]} "refs" {"__" ["\"hello\"" "\"hello\"" "\"better\"" "\"better!!!\"" '(dosync (ref-set the-world 0)) - ] "___" ['(comp exclamator exclamator exclamator) '(fn [x] (+ 20 x))]}