Created
December 19, 2015 20:59
-
-
Save domgetter/e64c15660b707c10299b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; without transducers | |
(defn notify [n] | |
(println (str "Doing something to: " n)) | |
n) | |
(defn notify-and-add-up | |
([] 0) | |
([result] result) | |
([result input] (+ result (notify input))) | |
([result input & inputs] | |
(+ result (apply notify input inputs)))) | |
(reduce notify-and-add-up 0 '(1 2 3)) | |
;; with transducers: | |
(defn notify [n] | |
(println (str "Doing something to: " n)) | |
n) | |
(def notify-and-add-up ((map notify) +)) | |
(reduce notify-and-add-up 0 '(1 2 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment