Skip to content

Instantly share code, notes, and snippets.

@clojj
Created February 23, 2015 12:50
Show Gist options
  • Save clojj/31820b44349a79e63ae6 to your computer and use it in GitHub Desktop.
Save clojj/31820b44349a79e63ae6 to your computer and use it in GitHub Desktop.
peek into transducing
(ns transpeek.core
(:gen-class)
(:import (java.util ArrayList)))
(defn map-
([f]
(fn [rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(rf result (f input)))
([result input & inputs]
(rf result (apply f input inputs)))))))
(defn peek-xform [xform]
(let [list (ArrayList.)]
[(fn [rf]
(let [rf- (xform rf)]
(fn
([] (rf-))
([result] (rf- result))
([result input]
(let [res (rf- result input)]
(.add list res)
res))
([result input & inputs]
(rf- result inputs)))))
list]))
(def xform (map- inc))
#_(let [value (peek-xform xform)]
(into [] (first value) [0 1 2 3 4])
(clojure.pprint/pprint (last value)))
(let [value (peek-xform xform)]
(transduce (first value) conj [0 1 2 3 4])
(clojure.pprint/pprint (last value)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment