Last active
August 29, 2015 14:11
-
-
Save trikitrok/af876eb83426c4dc9ace to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def test-address | |
{:street-address "123 Test Lane" | |
:city "Testerville" | |
:state "TX"}) | |
;"Destructuring is an arbiter: it breaks up arguments" | |
(= "__" ((fn [[a b]] (str b a)) | |
[:foo :bar])) | |
;"Whether in function definitions" | |
(= (str "First comes love, " | |
"then comes marriage, " | |
"then comes Clojure with the baby carriage") | |
((fn [[a b c]] "__") | |
["love" "marriage" "Clojure"])) | |
;"Or in let expressions" | |
(= "Rich Hickey aka The Clojurer aka Go Time aka Macro Killah" | |
(let [[first-name last-name & aliases] | |
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Macro Killah")] | |
"__")) | |
;"You can regain the full argument if you like arguing" | |
(= {:original-parts ["Stephen" "Hawking"] :named-parts {:first "Stephen" :last "Hawking"}} | |
(let [[first-name last-name :as full-name] ["Stephen" "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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment