Skip to content

Instantly share code, notes, and snippets.

@domgetter
Created December 19, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domgetter/e64c15660b707c10299b to your computer and use it in GitHub Desktop.
Save domgetter/e64c15660b707c10299b to your computer and use it in GitHub Desktop.
;; 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