FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added brief description of transducers · whitethief/clojure-through-code@86194fd · GitHub

Repository navigation

Commit 86194fd

Browse files
Added brief description of transducers
1 parent 20ad864 commit 86194fd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎src/clojure_through_code/core_async.clj‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@
5858
;; Create a channel with a simple transducer.
5959
;; The transducer increments the value of the message added to the channel.
6060

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+
6173
(def channel-increment (chan 1 (map inc)))
6274

6375
(put! channel-increment 41)
@@ -86,6 +98,7 @@
8698

8799
(take! channel-filtered-values #(println % "filtered results from channel"))
88100

101+
;; if we could see whats in the channel we would know when the transducer works...
89102

90103

91104
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL