Finished koan 15
This commit is contained in:
parent
37bf3d22bf
commit
40755feb94
1 changed files with 26 additions and 15 deletions
|
|
@ -8,37 +8,48 @@
|
|||
|
||||
(meditations
|
||||
"Destructuring is an arbiter: it breaks up arguments"
|
||||
(= __ ((fn [[a b]] (str b a))
|
||||
(= ":bar:foo"
|
||||
((fn [[a b]] (str b a))
|
||||
[:foo :bar]))
|
||||
|
||||
"Whether in function definitions"
|
||||
(= (str "An Oxford comma list of apples, "
|
||||
"oranges, "
|
||||
"and pears.")
|
||||
((fn [[a b c]] __)
|
||||
(=
|
||||
(str "An Oxford comma list of apples, "
|
||||
"oranges, " "and pears.")
|
||||
((fn [[a b c]]
|
||||
(str "An Oxford comma list of " a ", " b ", and " c "."))
|
||||
["apples" "oranges" "pears"]))
|
||||
|
||||
"Or in let expressions"
|
||||
(= "Rich Hickey aka The Clojurer aka Go Time aka Lambda Guru"
|
||||
(let [[first-name last-name & aliases]
|
||||
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Lambda Guru")]
|
||||
__))
|
||||
(apply str (interpose " " (apply list first-name last-name
|
||||
(interleave (repeat "aka") aliases))))))
|
||||
|
||||
"You can regain the full argument if you like arguing"
|
||||
(= {:original-parts ["Stephen" "Hawking"] :named-parts {:first "Stephen" :last "Hawking"}}
|
||||
(= {:original-parts ["Stephen" "Hawking"]
|
||||
:named-parts {:first "Stephen"
|
||||
:last "Hawking"}}
|
||||
(let [[first-name last-name :as full-name] ["Stephen" "Hawking"]]
|
||||
__))
|
||||
{:original-parts full-name
|
||||
:named-parts {:first first-name
|
||||
:last last-name}}))
|
||||
|
||||
"Break up maps by key"
|
||||
(= "123 Test Lane, Testerville, TX"
|
||||
(let [{street-address :street-address, city :city, state :state} test-address]
|
||||
__))
|
||||
(let [{street-address :street-address,
|
||||
city :city,
|
||||
state :state} test-address]
|
||||
(str street-address ", " city ", " state)))
|
||||
|
||||
"Or more succinctly"
|
||||
(= "123 Test Lane, Testerville, TX"
|
||||
(let [{:keys [street-address __ __]} test-address]
|
||||
__))
|
||||
(let [{:keys [street-address city state]} test-address]
|
||||
(str street-address ", " city ", " state)))
|
||||
|
||||
"All together now!"
|
||||
(= "Test Testerson, 123 Test Lane, Testerville, TX"
|
||||
(___ ["Test" "Testerson"] test-address)))
|
||||
((fn [[first-name last-name] {:keys [street-address city state]}]
|
||||
(str first-name " " last-name ", " street-address ", " city ", " state))
|
||||
["Test" "Testerson"] test-address)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue