Merge branch 'friendlier-koans'
This commit is contained in:
commit
f30feb25fe
@ -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})))
|
||||||
|
@ -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}])))
|
||||||
|
Loading…
Reference in New Issue
Block a user