         vec
         ;(r/take limit)
         (r/map counter)
+        (r/map inc)
+        (r/filter odd?)
         (r/fold 8 + +)
         ))
 

(ns clojure-club.playground.mbastian
  (:require [clojure.core.reducers :as r]))

(defn work-proxy [input]  (Thread/sleep input)  1)



(defn counter [thunk]
  (thunk))

;Plain old threading
(defn baseline [limit delay]
  (->> (slow-range limit delay) (map counter) (map inc) (filter odd?) (reduce +)))

;pmap
(defn baseline+pmap [limit delay]
  (->> (slow-range limit delay) (pmap counter) (map inc) (filter odd?) (reduce +)))

;Not reduced since it's not in a vec
(defn slow-range-reducer [limit delay]
  (->> (slow-range limit delay) (r/map counter) (r/map inc) (r/filter odd?) (r/fold 8 + +)))

;Reduced since it's in a vec
(defn slow-rangev-reducer [limit delay]
  (->> (slow-rangev limit delay) (r/map counter) (r/map inc) (r/filter odd?) (r/fold 8 + +)))

(def rxf #(->> % (r/map counter) (r/map inc) (r/filter odd?)))

(defn slow-rangev-reducer-pipe [limit delay]
  (->> (slow-rangev limit delay) rxf (r/fold 8 + +)))

;Transducers compose pipelines
(def xf
  (comp (map counter) (map inc) (filter odd?)))

;This is not executed in parallel. When would I transduce vs. reduce?
(defn slow-rangev-transducer [limit delay]
  (transduce xf + (slow-rangev limit delay)))

(tufte/add-basic-println-handler! {})
#_(profile
  {:dynamic? true}
  (let [samples 40 delay 100]
    (dotimes [_ 5]
      (p :baseline (do (baseline samples delay)))
      (p :baseline+pmap (do (baseline+pmap samples delay)))
      ;(p :slow-range-reducer (do (slow-range-reducer samples delay)))
      ;(p :slow-rangev-reducer (do (slow-rangev-reducer samples delay)))
      (p :slow-rangev-reducer-pipe (do (slow-rangev-reducer-pipe samples delay)))
      ;(p :slow-rangev-transducer (do (slow-rangev-transducer samples delay)))
      )))

;Think of work proxy as set amount of calculation we want to do.
;What I was trying to do was get the reducers to run each thunk in parallel.
