Skip to content

Instantly share code, notes, and snippets.

@clojj
Created Feb 23, 2015
Embed
What would you like to do?
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