diff --git a/.gorilla-port b/.gorilla-port index 88b4bbf..21b9509 100644 --- a/.gorilla-port +++ b/.gorilla-port @@ -1 +1 @@ -42814 \ No newline at end of file +43708 \ No newline at end of file diff --git a/README.md b/README.md index e69de29..098bc48 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,6 @@ +# following + +||| +|--|--| +|a | b| +|c | d| diff --git a/resources/public/images/crates.jpg b/resources/public/images/crates.jpg new file mode 100644 index 0000000..e7a3a93 Binary files /dev/null and b/resources/public/images/crates.jpg differ diff --git a/resources/public/images/devil.jpg b/resources/public/images/devil.jpg new file mode 100644 index 0000000..f45bee8 Binary files /dev/null and b/resources/public/images/devil.jpg differ diff --git a/resources/public/images/heavy-bag.jpeg b/resources/public/images/heavy-bag.jpeg new file mode 100644 index 0000000..ea4c5e9 Binary files /dev/null and b/resources/public/images/heavy-bag.jpeg differ diff --git a/resources/public/images/laptop-bag.jpg b/resources/public/images/laptop-bag.jpg new file mode 100644 index 0000000..48f025e Binary files /dev/null and b/resources/public/images/laptop-bag.jpg differ diff --git a/resources/public/images/load-airplane.jpg b/resources/public/images/load-airplane.jpg new file mode 100644 index 0000000..8b24366 Binary files /dev/null and b/resources/public/images/load-airplane.jpg differ diff --git a/resources/public/images/unload.jpg b/resources/public/images/unload.jpg new file mode 100644 index 0000000..3a1d803 Binary files /dev/null and b/resources/public/images/unload.jpg differ diff --git a/src/clj/transducerpres/presentation.clj b/src/clj/transducerpres/presentation.clj index b97fd93..0a570fa 100644 --- a/src/clj/transducerpres/presentation.clj +++ b/src/clj/transducerpres/presentation.clj @@ -4,11 +4,16 @@ [transducerpres.slides.what :refer [what-is-a-tranducer]] [transducerpres.slides.how :refer [how-to-create-slides]] [transducerpres.slides.revisiting-map :refer [revisiting-map-slides]] + [transducerpres.slides.analogy :refer [rich-hickey-analogy]] + [transducerpres.slides.transducer-function :refer [transducer-function-slides]] )) (def presentation - [intro-slide + [ + intro-slide roadmap-slide what-is-a-tranducer + rich-hickey-analogy how-to-create-slides - revisiting-map-slides]) + revisiting-map-slides + transducer-function-slides]) diff --git a/src/clj/transducerpres/slides/analogy.clj b/src/clj/transducerpres/slides/analogy.clj new file mode 100644 index 0000000..5b1d63b --- /dev/null +++ b/src/clj/transducerpres/slides/analogy.clj @@ -0,0 +1,68 @@ +(ns transducerpres.slides.analogy + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide clj-code markdown-slide markdown-part img]])) + +(defmarkdownslide title + "## Rich Hickey's analogy" + "> talk: https://www.youtube.com/watch?v=6mTbuzafcII") + +(defmarkdownslide the-analogy + "### To load an airplane you need to...") + +(defslide getting-the-luggages + [:h4 "1 : You start with some luggage crates"] + (img "crates.jpg")) + +(defslide unpack-the-crates + [:h4 "2 : unpack the luggaes from the crates"] + (img "unload.jpg")) + +(defslide remove-bags + [:h4 "3 : remove bags that contain laptop"] + (img "laptop-bag.jpg")) + +(defslide label-heavy-bags + [:h4 "4 : label heavy bags"] + (img "heavy-bag.jpeg")) + +(defslide load-the-airplane + [:h4 "5 : load the airplane"] + (img "load-airplane.jpg")) + +(defmarkdownslide recap-the-analogy + "### Recap the analogy" + "| Physical action/thing | Function/data structure |" + "|:--------------------------------|:------------------------|" + "|crates of bags | seq of seq of Map |" + "|un-pack the crates | `mapcat` |" + "|remove bags that contains laptop | `filtering` |" + "|label heavy bags | `map` |" + "|airplane | sequence |") + +(defslide lesson-from-the-analogy + [:h3 "Lessons from the analogy"]) + +(defmarkdownslide lesson-from-the-analogy-1 + "#### Lesson number 1" + "> The origin and destination of the bags do not matter" + "* receiving the crates in a truck or on a conveyor belt is the same" + "* Loading a ship or an airplane is the same thing") + +(defmarkdownslide lesson-from-the-analogy-2 + "#### Lesson number 2" + "> There is no need to place the bags on a conveyor belt between each step" + ) + +; Rich Hickey +(defslide rich-hickey-analogy + title + the-analogy + getting-the-luggages + unpack-the-crates + remove-bags + label-heavy-bags + load-the-airplane + recap-the-analogy + lesson-from-the-analogy + lesson-from-the-analogy-1 + lesson-from-the-analogy-2 + ) diff --git a/src/clj/transducerpres/slides/how.clj b/src/clj/transducerpres/slides/how.clj index c25af93..5785760 100644 --- a/src/clj/transducerpres/slides/how.clj +++ b/src/clj/transducerpres/slides/how.clj @@ -13,7 +13,15 @@ (def transducer-functions (clojure.string/split "map cat mapcat filter remove take take-while take-nth drop drop-while replace partition-by partition-all keep keep-indexed map-indexed distinct interpose dedupe random-sample" #" ")) (defn transducer-function-list [] - (clojure.string/join "\n" (map func-link-bullet transducer-functions))) + (let [n-cols 4 + rows (partition n-cols transducer-functions) + row-format (str (reduce str "|" (repeat n-cols "%s|")) "\n") + format-table-row (fn [columns] (apply format (cons row-format columns))) + table-header (str (format-table-row (repeat n-cols " ")) (format-table-row (repeat n-cols "--"))) + table-rows-xform (map format-table-row) + ret (transduce table-rows-xform str table-header rows) + ] + ret)) (defmarkdownslide how-to-create "#### How to create transducers?" diff --git a/src/clj/transducerpres/slides/revisiting_map.clj b/src/clj/transducerpres/slides/revisiting_map.clj index d00b7bd..a83a792 100644 --- a/src/clj/transducerpres/slides/revisiting_map.clj +++ b/src/clj/transducerpres/slides/revisiting_map.clj @@ -9,7 +9,7 @@ (markdown-part "### Naive implementation of map") (python-code "def naive_map(fn, lst):" - " ret = [0]*len(lst)" + " ret = [0] * len(lst)" " for i in range(len(lst)):" " ret[i] = fn(lst[i])" " return ret") @@ -20,24 +20,54 @@ (markdown-part "### clojuresque way of implementing map") (clj-code "(defn my-map [f coll]" - " (loop [ret (list) coll coll]" + " (loop [ret [] coll coll]" " (if (empty? coll)" " ret" - " (recur (cons (f (first coll)) ret) (rest coll)))))" + " (recur (conj ret (f (first coll))) (rest coll)))))" )) +(defslide conj-wirdness + (markdown-part "### `conj` is a weird beast") + (clj-code + "(conj [1 2 3] 99)" + ";; [1 2 3 99]") + (clj-code + "(conj '(1 2 3) 99)" + ";; (99 1 2 3)") + (clj-code + "(conj #{1 2 3} 99)" + ";; #{1 2 99 3}") + (clj-code + "(conj {:key1 1 :key2 2} [:key3 3])" + ";; {:key1 1, :key2 2, :key3 3}")) + (defslide reduce-way (markdown-part "### A more elegant way") (clj-code "(defn my-map [f coll]" - " (reduce #(cons (f %2) %1) (list) coll))")) + " (reduce #(conj %1 (f %2)) [] coll))")) -(defslide extracting-reduce-function - (markdown-part "### We can go further and extract the reduce function") +(defslide other-map-like-function + (markdown-part "#### many other map-like functions can be written similarly") (clj-code - "(defn [reduce-function]" - " (defn my-map [f]" - " (reduce-function (f (first coll)) coll))")) + "(defn my-map [f coll]" + " (reduce #(conj %1 (f %2)) [] coll))") + (clj-code + "(defn my-filter [pred coll]" + " (reduce #(if (pred %2) (conj %1 %2) %1) [] coll))") + (clj-code + "(defn my-mapcat [pred coll]" + " (reduce (fn [r x](reduce conj r (f x))) [] coll))") + ) + +(defslide the-main-issue + (markdown-part + "#### The main issue here the `conj`" + " " + "* `conj` here yells \"collection\"" + "* `conj` creates intermediate data structures everywhere" + " " + )) @@ -46,5 +76,8 @@ intro-slide naive-way clojuresque-way + conj-wirdness reduce-way - extracting-reduce-function) + other-map-like-function + the-main-issue + ) diff --git a/src/clj/transducerpres/slides/transducer_function.clj b/src/clj/transducerpres/slides/transducer_function.clj new file mode 100644 index 0000000..4afa917 --- /dev/null +++ b/src/clj/transducerpres/slides/transducer_function.clj @@ -0,0 +1,14 @@ +(ns transducerpres.slides.transducer-function + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide markdown-part clj-code python-code img]])) + + +(defmarkdownslide intro-slide + "#### transducer functions!!") + +(defslide devil + (img "devil.jpg")) + + +(defslide transducer-function-slides + intro-slide + devil) diff --git a/src/clj/transducerpres/slides/util.clj b/src/clj/transducerpres/slides/util.clj index b2a32d4..79827af 100644 --- a/src/clj/transducerpres/slides/util.clj +++ b/src/clj/transducerpres/slides/util.clj @@ -29,3 +29,6 @@ (defn fa [name] [:i {:class (str "fa fa-" name) :aria-hidden "true"}]) + +(defn img [name] + [:img {:src (str "/images/" name)}]) diff --git a/src/clj/transducerpres/slides/what.clj b/src/clj/transducerpres/slides/what.clj index cb5be15..9926641 100644 --- a/src/clj/transducerpres/slides/what.clj +++ b/src/clj/transducerpres/slides/what.clj @@ -1,5 +1,5 @@ (ns transducerpres.slides.what - (:require [transducerpres.slides.util :refer [defslide defmarkdownslide clj-code markdown-slide markdown-part]])) + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide clj-code markdown-slide markdown-part fa]])) (defslide title [:h3 "What is a Transducer?"]) @@ -15,10 +15,25 @@ "A **transducer** (sometimes referred to as **xform** or **xf**) is a " "transformation from one reducing function to another") +(defmarkdownslide rich-hickey-definition + "#### According to Rich Hickey " + "* extract the **essence** of map, filter et al" + "* away of the functions that transform sequences/collections" + "* so they can be use elsewhere" + "* recasting them as **process transformation**") + (defmarkdownslide does-not-help-much - "#### That does not help much" + "#### That does not help much (the first time)" "Instead let take a look at what transducer try to solve") +(defslide example-selection + (markdown-part + "#### let's look at an example" + "We have two options..." + "1. look at code example" + "2. look at a very nice analogy") + (fa "question")) + (defslide classical-problem (markdown-part "#### Classical problem: $ \\sum_{n=0}^{N-1} 2 \\cdot n + 3 $") @@ -65,14 +80,16 @@ )) (defmarkdownslide transducer-formal-definition - "Hence a **transducer** is a data pipeline \"functional interface\"" + "Hence, a **transducer** is a data pipeline \"functional interface\"" "that is un aware of the underlying data structure.") (defslide what-is-a-tranducer title wikipedia-definition clojuredoc-definition + rich-hickey-definition does-not-help-much + example-selection classical-problem classical-problem-with-channel classical-problem-with-transducer