diff --git a/src/clj/transducerpres/presentation.clj b/src/clj/transducerpres/presentation.clj index 0a570fa..0780aab 100644 --- a/src/clj/transducerpres/presentation.clj +++ b/src/clj/transducerpres/presentation.clj @@ -1,19 +1,32 @@ (ns transducerpres.presentation - (:require [transducerpres.slides.intro :refer [intro-slide]] + (:require [transducerpres.slides.util :refer [defmarkdownslide]] + [transducerpres.slides.intro :refer [intro-slide]] [transducerpres.slides.roadmap :refer [roadmap-slide]] [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]] + [transducerpres.slides.stopping :refer [stopping-slides]] + [transducerpres.slides.state :refer [state-slides]] + [transducerpres.slides.arities :refer [arities-slides]] + [transducerpres.slides.completion :refer [completion-slides]] + )) +(defmarkdownslide questions + "questions?") (def presentation - [ - intro-slide + [intro-slide roadmap-slide what-is-a-tranducer rich-hickey-analogy how-to-create-slides revisiting-map-slides - transducer-function-slides]) + transducer-function-slides + stopping-slides + state-slides + arities-slides + completion-slides + questions + ]) diff --git a/src/clj/transducerpres/slides/arities.clj b/src/clj/transducerpres/slides/arities.clj new file mode 100644 index 0000000..9c08ffa --- /dev/null +++ b/src/clj/transducerpres/slides/arities.clj @@ -0,0 +1,32 @@ +(ns transducerpres.slides.arities + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide markdown-part clj-code img]])) + +(defmarkdownslide intro-slide + "#### The transducer function **must** support two more arities") + +(defmarkdownslide one-arity + "#### completion of process" + "When a process terminates, the arity one transducer function" + "is called to allow transducer to do extra things") + +(defmarkdownslide zero-arity + "#### initial reducing value" + "To allow initial values, trasducer **must** have an arity" + "zero function that calls the step function without any argument") + +(defslide real-world-example + (markdown-part "real world example") + (clj-code + "(defn map [f]" + " (fn [rf]" + " (fn" + " ([] (rf))" + " ([result] (rf result))" + " ([result input]" + " (rf result (f input))))))")) + +(defslide arities-slides + intro-slide + one-arity + zero-arity + real-world-example) diff --git a/src/clj/transducerpres/slides/completion.clj b/src/clj/transducerpres/slides/completion.clj new file mode 100644 index 0000000..fde7d8e --- /dev/null +++ b/src/clj/transducerpres/slides/completion.clj @@ -0,0 +1,21 @@ +(ns transducerpres.slides.completion + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide markdown-part clj-code img]])) + + +(defmarkdownslide intro-slide + "#### Completion can do thing at the very end") + +(defmarkdownslide explanation + "#### Arity one moment" + "* The completion of the process is done at arity one" + "* It **must** finish by calling the step function with the result (arity one)") + +(defmarkdownslide going-to-sleep + "#### Going to sleep..." + "https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L7115") + + +(defslide completion-slides + intro-slide + explanation + going-to-sleep) diff --git a/src/clj/transducerpres/slides/state.clj b/src/clj/transducerpres/slides/state.clj new file mode 100644 index 0000000..2836a79 --- /dev/null +++ b/src/clj/transducerpres/slides/state.clj @@ -0,0 +1,25 @@ +(ns transducerpres.slides.state + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide markdown-part clj-code img]])) + +(defmarkdownslide intro-slide + "#### Creating transducers that has state") + +(defslide thousand-words-example + (markdown-part "#### thousand words example") + (clj-code + "(defn take [n]" + " (fn [step]" + " (let [nv (volatile! n)]" + " (fn [result input]" + " (let [n @nv" + " nn (vswap! nv dec)" + " result (if (pos? n) (step result input) result)]" + " (if (not (pos? nn))" + " (reduced result)" + " result))))))" +)) + + +(defslide state-slides + intro-slide + thousand-words-example) diff --git a/src/clj/transducerpres/slides/stopping.clj b/src/clj/transducerpres/slides/stopping.clj new file mode 100644 index 0000000..deb9237 --- /dev/null +++ b/src/clj/transducerpres/slides/stopping.clj @@ -0,0 +1,48 @@ +(ns transducerpres.slides.stopping + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide markdown-part clj-code img]])) + +(defmarkdownslide intro-slide + "#### Stopping transducing process") + +(defmarkdownslide goal + "#### goal" + "* transducers must be capable of calling 'completion'" + "* step functions must be capable of calling 'completion'") + +(defmarkdownslide stopping-in-reduce + "#### `reduce` already support stopping the process" + "* `(reduced 3)` wraps 3 in a Reduced wrapper" + "* `(reduced? x)` tells is a value is wrapped" + "* `(deref x)` or `@x` will get you the wrapped value") + +(defmarkdownslide reduced-transducer + "#### transducer **must** support the reduced \"interface\"" + "* step functions can return reduced value" + "* if a transducer get a reduced value from a nested step," + " it must never call that step function again with input") + +(defmarkdownslide stopping-process + "#### reducing process **must** the rules too" + "* if a step function returns a reduced value it" + " the processs must not supply anymore input" + " to the step function" + "* the dereference value is the final accumulated value") + +(defslide take-while-example + (markdown-part "#### take-while example") + (clj-code + "(defn take-while [pred]" + " (fn [step]" + " (fn [res x]" + " (if (pred x)" + " (step res x)" + " (reduced res)))))")) + + +(defslide stopping-slides + intro-slide + goal + stopping-in-reduce + stopping-process + take-while-example + ) diff --git a/src/clj/transducerpres/slides/transducer_function.clj b/src/clj/transducerpres/slides/transducer_function.clj index 3c63f5a..00f1ace 100644 --- a/src/clj/transducerpres/slides/transducer_function.clj +++ b/src/clj/transducerpres/slides/transducer_function.clj @@ -1,5 +1,5 @@ (ns transducerpres.slides.transducer-function - (:require [transducerpres.slides.util :refer [defslide defmarkdownslide markdown-part clj-code python-code img]])) + (:require [transducerpres.slides.util :refer [defslide defmarkdownslide markdown-part clj-code img]])) (defslide intro-slide