 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; filter, some
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (fact "journal entries for human less than 5 liters"
   (filter #(< (:human %) 5) food-journal)

  {:human human
   :critter critter})

(fact
  (map unify-diet-data human-consumption critter-consumption)
  => '({:human 8.1, :critter 0.0}
       {:human 7.3, :critter 0.2}


;; Programming to Abstractions

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; one function on different data structures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn titleize
  [topic]
  (str topic " for the Brave and True"))

(facts "test titleize"

  (fact "titleize a vector"
    (map titleize ["Hamsters" "Ragnarok"])
    => '("Hamsters for the Brave and True" "Ragnarok for the Brave and True"))

  (fact "titleize a list"
    (map titleize '("Empathy" "Decorating"))
    => '("Empathy for the Brave and True" "Decorating for the Brave and True"))

  (fact
    (map titleize #{"Elbows" "Soap Carving"})
    => (contains '("Soap Carving for the Brave and True" "Elbows for the Brave and True")
                 :in-any-order)))

(defn label-key-val
  [[key val]]
  (str "key: " key ", val: " val))

(fact
  (map label-key-val {:name "Edward"
                      :occupation "perennial high-schooler"})
  => (contains '("key: :name, val: Edward"
                 "key: :occupation, val: perennial high-schooler")
               :in-any-order))

(fact "transform a map by applying a function to each of the map's values:"
  (map (fn [[key val]] [key (inc val)])
     {:max 30 :min 10})
  => (contains '([:max 31] [:min 11])
               :in-any-order))

(fact "convert back 'into' a map"
  (into {}
      (map (fn [[key val]] [key (inc val)])
           {:max 30 :min 10}))
  => {:max 31, :min 11})


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; the sequence abstraction:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The ISeq interface - alows many data structurs to act as sequences

(fact "'identity' returns whatever is passed to it."
  (identity "Stefan Salvatore from Vampire Diaries")
  => "Stefan Salvatore from Vampire Diaries")


(fact "a non sequenctial collection is conveted to a sequence using 'map' and 'identity'"
  (map identity {:name "Bill Compton" :occupation "Dead mopey guy"})
  => (contains '([:name "Bill Compton"] [:occupation "Dead mopey guy"]) :in-any-order))

(fact "the seq function converts a map data structure into a sequence of vectors"
  (seq {:name "Bill Compton" :occupation "Dead mopey guy"})
  => (contains '([:name "Bill Compton"] [:occupation "Dead mopey guy"]) :in-any-order))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; sequence function examples

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; map
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(fact "'map' applies a function over a sequence"
  (map inc [1 2 3])
  => '(2 3 4))

(fact "'map' applied over multiple sequences"
  (map str ["a" "b" "c"] ["A" "B" "C"])
  => '("aA" "bB" "cC")
  (map + [1 2 3] [1 2 3])
