blah blah blag
This commit is contained in:
1 parent
1e9d527608
commit
632cfb7c20
15 files changed
+170
-16
No files matched your search
+1
-1
@@ -1 +1 @@
|
|||||||
42814
|
43708
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 190 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 660 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
@@ -4,11 +4,16 @@
|
|||||||
[transducerpres.slides.what :refer [what-is-a-tranducer]]
|
[transducerpres.slides.what :refer [what-is-a-tranducer]]
|
||||||
[transducerpres.slides.how :refer [how-to-create-slides]]
|
[transducerpres.slides.how :refer [how-to-create-slides]]
|
||||||
[transducerpres.slides.revisiting-map :refer [revisiting-map-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
|
(def presentation
|
||||||
[intro-slide
|
[
|
||||||
|
intro-slide
|
||||||
roadmap-slide
|
roadmap-slide
|
||||||
what-is-a-tranducer
|
what-is-a-tranducer
|
||||||
|
rich-hickey-analogy
|
||||||
how-to-create-slides
|
how-to-create-slides
|
||||||
revisiting-map-slides])
|
revisiting-map-slides
|
||||||
|
transducer-function-slides])
|
||||||
@@ -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
|
||||||
|
)
|
||||||
@@ -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" #" "))
|
(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 []
|
(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
|
(defmarkdownslide how-to-create
|
||||||
"#### How to create transducers?"
|
"#### How to create transducers?"
|
||||||
|
|||||||
@@ -20,24 +20,54 @@
|
|||||||
(markdown-part "### clojuresque way of implementing map")
|
(markdown-part "### clojuresque way of implementing map")
|
||||||
(clj-code
|
(clj-code
|
||||||
"(defn my-map [f coll]"
|
"(defn my-map [f coll]"
|
||||||
" (loop [ret (list) coll coll]"
|
" (loop [ret [] coll coll]"
|
||||||
" (if (empty? coll)"
|
" (if (empty? coll)"
|
||||||
" ret"
|
" 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
|
(defslide reduce-way
|
||||||
(markdown-part "### A more elegant way")
|
(markdown-part "### A more elegant way")
|
||||||
(clj-code
|
(clj-code
|
||||||
"(defn my-map [f coll]"
|
"(defn my-map [f coll]"
|
||||||
" (reduce #(cons (f %2) %1) (list) coll))"))
|
" (reduce #(conj %1 (f %2)) [] coll))"))
|
||||||
|
|
||||||
(defslide extracting-reduce-function
|
(defslide other-map-like-function
|
||||||
(markdown-part "### We can go further and extract the reduce function")
|
(markdown-part "#### many other map-like functions can be written similarly")
|
||||||
(clj-code
|
(clj-code
|
||||||
"(defn [reduce-function]"
|
"(defn my-map [f coll]"
|
||||||
" (defn my-map [f]"
|
" (reduce #(conj %1 (f %2)) [] coll))")
|
||||||
" (reduce-function (f (first coll)) 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
|
intro-slide
|
||||||
naive-way
|
naive-way
|
||||||
clojuresque-way
|
clojuresque-way
|
||||||
|
conj-wirdness
|
||||||
reduce-way
|
reduce-way
|
||||||
extracting-reduce-function)
|
other-map-like-function
|
||||||
|
the-main-issue
|
||||||
|
)
|
||||||
@@ -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)
|
||||||
@@ -29,3 +29,6 @@
|
|||||||
|
|
||||||
(defn fa [name]
|
(defn fa [name]
|
||||||
[:i {:class (str "fa fa-" name) :aria-hidden "true"}])
|
[:i {:class (str "fa fa-" name) :aria-hidden "true"}])
|
||||||
|
|
||||||
|
(defn img [name]
|
||||||
|
[:img {:src (str "/images/" name)}])
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
(ns transducerpres.slides.what
|
(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
|
(defslide title
|
||||||
[:h3 "What is a Transducer?"])
|
[:h3 "What is a Transducer?"])
|
||||||
@@ -15,10 +15,25 @@
|
|||||||
"A **transducer** (sometimes referred to as **xform** or **xf**) is a "
|
"A **transducer** (sometimes referred to as **xform** or **xf**) is a "
|
||||||
"transformation from one reducing function to another")
|
"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
|
(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")
|
"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
|
(defslide classical-problem
|
||||||
(markdown-part
|
(markdown-part
|
||||||
"#### Classical problem: $ \\sum_{n=0}^{N-1} 2 \\cdot n + 3 $")
|
"#### Classical problem: $ \\sum_{n=0}^{N-1} 2 \\cdot n + 3 $")
|
||||||
@@ -65,14 +80,16 @@
|
|||||||
))
|
))
|
||||||
|
|
||||||
(defmarkdownslide transducer-formal-definition
|
(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.")
|
"that is un aware of the underlying data structure.")
|
||||||
|
|
||||||
(defslide what-is-a-tranducer
|
(defslide what-is-a-tranducer
|
||||||
title
|
title
|
||||||
wikipedia-definition
|
wikipedia-definition
|
||||||
clojuredoc-definition
|
clojuredoc-definition
|
||||||
|
rich-hickey-definition
|
||||||
does-not-help-much
|
does-not-help-much
|
||||||
|
example-selection
|
||||||
classical-problem
|
classical-problem
|
||||||
classical-problem-with-channel
|
classical-problem-with-channel
|
||||||
classical-problem-with-transducer
|
classical-problem-with-transducer
|
||||||
|
|||||||
Reference in new issue
Block a user