This file contains hidden or 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
(defn my-fn [result {:keys [name employer]}] | |
(update-in result [employer] conj name)) | |
(reduce my-fn {} | |
[{:name "jay fields", :current-city "new york", :employer "drw.com"} | |
{:name "john dydo", :current-city "new york", :employer "drw.com"} | |
{:name "mike ward", :current-city "chicago", :employer "drw.com"} | |
{:name "chris george", :current-city "new york", :employer "thoughtworks.com"}]) |
This file contains hidden or 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
(->> [{:name "jay fields", :current-city "new york", :employer "drw.com"} | |
{:name "john dydo", :current-city "new york", :employer "drw.com"} | |
{:name "mike ward", :current-city "chicago", :employer "drw.com"} | |
{:name "chris george", :current-city "new york", :employer "thoughtworks.com"}] | |
(map (juxt :employer (comp list :name))) | |
(map (partial apply hash-map)) | |
(apply merge-with concat)) |
This file contains hidden or 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
(reduce (fn [result {:keys [name employer]}] (update-in result [employer] conj name)) {} | |
[{:name "jay fields", :current-city "new york", :employer "drw.com"} | |
{:name "john dydo", :current-city "new york", :employer "drw.com"} | |
{:name "mike ward", :current-city "chicago", :employer "drw.com"} | |
{:name "chris george", :current-city "new york", :employer "thoughtworks.com"}]) |
This file contains hidden or 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
;;; I prefer | |
(filter (comp #{"new york"} :current-city) | |
[{:name "jay fields", :current-city "new york", :employer "drw.com"} | |
{:name "john dydo", :current-city "new york", :employer "drw.com"} | |
{:name "mike ward", :current-city "chicago", :employer "drw.com"} | |
{:name "chris george", :current-city "new york", :employer "thoughtworks.com"}]) | |
;;; over | |
(filter #(= "new york" (:current-city %)) | |
[{:name "jay fields", :current-city "new york", :employer "drw.com"} |
This file contains hidden or 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
(require 'clojure.set) | |
(clojure.set/join [{:current-city "new york"}] | |
[{:name "jay fields", :current-city "new york", :employer "drw.com"} | |
{:name "john dydo", :current-city "new york", :employer "drw.com"} | |
{:name "mike ward", :current-city "chicago", :employer "drw.com"} | |
{:name "chris george", :current-city "new york", :employer "thoughtworks.com"}]) |
This file contains hidden or 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
(expect (interaction (one "hello" {:a :b :c {:dd :ee :ff :gg}})) | |
(do | |
(one "hello") | |
(one "hello" "world" "here") | |
(one "hello" {:a 1 2 3}))) | |
failure in (failure_examples.clj:154) : failure.failure-examples | |
expected: (one "hello" {:a :b, :c {:ff :gg, :dd :ee}}) once |
This file contains hidden or 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
(ns blog) | |
(def all-updates (atom {})) | |
(def last-update (atom {})) | |
(defn process-update [{:keys [src] :as update}] | |
(swap! all-updates update-in [src] conj update) | |
(swap! last-update assoc src update)) |
This file contains hidden or 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
(ns blog-expectations | |
(:use expectations | |
[blog :as b])) | |
(expect {"CNN" {:src "CNN" :headline "Election Update"} | |
"NY Times" {:src "NY Times" :headline "Movie Guide"}} | |
(do | |
(b/process-update {:src "NY Times" :headline "Market News"}) | |
(b/process-update {:src "CNN" :headline "Election Update"}) | |
(b/process-update {:src "NY Times" :headline "Movie Guide"}) |
This file contains hidden or 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
(ns blog-expectations | |
(:use expectations | |
[blog :as b])) | |
(expect {"CNN" {:src "CNN" :headline "Election Update"} | |
"NY Times" {:src "NY Times" :headline "Movie Guide"}} | |
(with-redefs [b/all-updates (atom {}) | |
b/last-update (atom {})] | |
(b/process-update {:src "NY Times" :headline "Market News"}) | |
(b/process-update {:src "CNN" :headline "Election Update"}) |
This file contains hidden or 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
(ns blog-expectations | |
(:use expectations | |
[blog :as b])) | |
(expect {"CNN" {:src "CNN" :headline "Election Update"} | |
"NY Times" {:src "NY Times" :headline "Movie Guide"}} | |
(redef-state [blog] | |
(b/process-update {:src "NY Times" :headline "Market News"}) | |
(b/process-update {:src "CNN" :headline "Election Update"}) | |
(b/process-update {:src "NY Times" :headline "Movie Guide"}) |