Created
February 23, 2015 12:50
-
-
Save clojj/31820b44349a79e63ae6 to your computer and use it in GitHub Desktop.
peek into transducing
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
(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