| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 20ad864 commit 86194fd
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,18 @@ | |||
| 58 | 58 | ;; Create a channel with a simple transducer. | |
| 59 | 59 | ;; The transducer increments the value of the message added to the channel. | |
| 60 | 60 | ||
| 61 | + ;; A transducer is an expression to transform values, that does not immediately | ||
| 62 | + ;; need those values. | ||
| 63 | + | ||
| 64 | + ;; In this example, map used the inc function to transform the collection of numbers | ||
| 65 | + | ||
| 66 | + ;; (map inc [1 2 3 4]) | ||
| 67 | + | ||
| 68 | + ;; To make this a transducer, we simply do not include the value to be transformed | ||
| 69 | + ;; (the collection in this example) in the expression | ||
| 70 | + ;; Our transducer equivalent is (map inc) | ||
| 71 | + ;; and the value to be transformed is passed at run time, when the transducer is called | ||
| 72 | + | ||
| 61 | 73 | (def channel-increment (chan 1 (map inc))) | |
| 62 | 74 | ||
| 63 | 75 | (put! channel-increment 41) | |
@@ -86,6 +98,7 @@ | |||
| 86 | 98 | ||
| 87 | 99 | (take! channel-filtered-values #(println % "filtered results from channel")) | |
| 88 | 100 | ||
| 101 | + ;; if we could see whats in the channel we would know when the transducer works... | ||
| 89 | 102 | ||
| 90 | 103 | ||
| 91 | 104 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments