Merge remote-tracking branch 'clojurebridge-minneapolis/master'

This commit is contained in:
Colin Jones 2015-07-06 07:13:05 -05:00
commit 37cc4ce04a
7 changed files with 30 additions and 31 deletions

2
.gitignore vendored
View File

@ -1,3 +1,4 @@
*~
bin bin
classes classes
lib lib
@ -8,4 +9,3 @@ target
.lein-deps-sum .lein-deps-sum
.lein-plugins .lein-plugins
.lein-repl-history .lein-repl-history

View File

@ -24,13 +24,13 @@
(= __ (not (= 1 nil))) (= __ (not (= 1 nil)))
"Strings, and keywords, and symbols: oh my!" "Strings, and keywords, and symbols: oh my!"
(= __ (= "foo" :foo 'foo)) (= __ (= "hello" :hello 'hello))
"Make a keyword with your keyboard" "Make a keyword with your keyboard"
(= :foo (keyword __)) (= :hello (keyword __))
"Symbolism is all around us" "Symbolism is all around us"
(= 'foo (symbol __)) (= 'hello (symbol __))
"When things cannot be equal, they must be different" "When things cannot be equal, they must be different"
(not= :fill-in-the-blank __)) (not= :fill-in-the-blank __))

View File

@ -1,5 +1,6 @@
(ns koans.04-sets (ns koans.04-sets
(:require [koan-engine.core :refer :all])) (:require [koan-engine.core :refer :all]
[clojure.set :as set]))
(meditations (meditations
"You can create a set by converting another collection" "You can create a set by converting another collection"
@ -12,10 +13,10 @@
(= __ (set '(1 1 2 2 3 3 4 4 5 5))) (= __ (set '(1 1 2 2 3 3 4 4 5 5)))
"You can ask clojure for the union of two sets" "You can ask clojure for the union of two sets"
(= __ (clojure.set/union #{1 2 3 4} #{2 3 5})) (= __ (set/union #{1 2 3 4} #{2 3 5}))
"And also the intersection" "And also the intersection"
(= __ (clojure.set/intersection #{1 2 3 4} #{2 3 5})) (= __ (set/intersection #{1 2 3 4} #{2 3 5}))
"But don't forget about the difference" "But don't forget about the difference"
(= __ (clojure.set/difference #{1 2 3 4 5} #{2 3 5}))) (= __ (set/difference #{1 2 3 4 5} #{2 3 5})))

View File

@ -1,14 +1,12 @@
(ns koans.07-conditionals (ns koans.07-conditionals
(:require [koan-engine.core :refer :all])) (:require [koan-engine.core :refer :all]))
(defn explain-defcon-level [exercise-term] (defn explain-exercise-velocity [exercise-term]
(case exercise-term (case exercise-term
:fade-out :you-and-what-army :bicycling "pretty fast"
:double-take :call-me-when-its-important :jogging "not super fast"
:round-house :o-rly :walking "not fast at all"
:fast-pace :thats-pretty-bad "is that even exercise?"))
:cocked-pistol :sirens
:say-what?))
(meditations (meditations
"You will face many decisions" "You will face many decisions"
@ -40,10 +38,10 @@
'doom 'doom
'more-doom)) 'more-doom))
"In case of emergency, sound the alarms" "In case of emergency, go fast"
(= :sirens (= "pretty fast"
(explain-defcon-level __)) (explain-exercise-velocity __))
"But admit it when you don't know what to do" "But admit it when you don't know what to do"
(= __ (= __
(explain-defcon-level :yo-mama))) (explain-exercise-velocity :watching-tv)))

View File

@ -24,5 +24,5 @@
(repeat 10 __)) (repeat 10 __))
"Iteration can be used for repetition" "Iteration can be used for repetition"
(= (repeat 100 :foo) (= (repeat 100 :hello)
(take 100 (iterate ___ :foo)))) (take 100 (iterate ___ :hello))))

View File

@ -12,16 +12,16 @@
[:foo :bar])) [:foo :bar]))
"Whether in function definitions" "Whether in function definitions"
(= (str "First comes love, " (= (str "An Oxford comma list of apples, "
"then comes marriage, " "oranges, "
"then comes Clojure with the baby carriage") "and pears.")
((fn [[a b c]] __) ((fn [[a b c]] __)
["love" "marriage" "Clojure"])) ["apples" "oranges" "pears"]))
"Or in let expressions" "Or in let expressions"
(= "Rich Hickey aka The Clojurer aka Go Time aka Macro Killah" (= "Rich Hickey aka The Clojurer aka Go Time aka Lambda Guru"
(let [[first-name last-name & aliases] (let [[first-name last-name & aliases]
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Macro Killah")] (list "Rich" "Hickey" "The Clojurer" "Go Time" "Lambda Guru")]
__)) __))
"You can regain the full argument if you like arguing" "You can regain the full argument if you like arguing"

View File

@ -19,20 +19,20 @@
"You can also group by a primary key" "You can also group by a primary key"
(= __ (= __
(group-by :id [{:id 1 :name "Bob"} (group-by :id [{:id 1 :name "Bob"}
{:id 2 :name "Mike"} {:id 2 :name "Jennifer"}
{:id 1 :last-name "Smith"} ])) {:id 1 :last-name "Smith"} ]))
"But be careful when you group by non-required key" "But be careful when you group by non-required key"
(= {"Bob" [{:name "Bob" :id 1}] (= {"Bob" [{:name "Bob" :id 1}]
"Mike" [{:name "Mike" :id 2}] "Jennifer" [{:name "Jennifer" :id 2}]
__ [{:last-name "Smith" :id 1}]} __ [{:last-name "Smith" :id 1}]}
(group-by :name [{:id 1 :name "Bob"} (group-by :name [{:id 1 :name "Bob"}
{:id 2 :name "Mike"} {:id 2 :name "Jennifer"}
{:id 1 :last-name "Smith"}])) {:id 1 :last-name "Smith"}]))
"The true power of group-by comes with custom functions" "The true power of group-by comes with custom functions"
(= __ (= __
(group-by #(if (:bad %) :naughty-list :nice-list) (group-by #(if (:bad %) :naughty-list :nice-list)
[{:name "Jimmy" :bad true} [{:name "Jimmy" :bad true}
{:name "Jack" :bad false} {:name "Anna" :bad false}
{:name "Joe" :bad true}]))) {:name "Joe" :bad true}])))