Last active
August 29, 2015 14:10
-
-
Save kotarak/e400a31e6217bc9649ef 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
(require '[transmuter.core :as t]) | |
(require '[transmuter.async :as at]) | |
; Not a dependency of transmuters. Must be provided | |
; separately by the application! | |
(require '[clojure.core.async :as async]) | |
(def input (range 1000000)) | |
; Pipeline definitions are vectors of pipes. | |
; May nest arbitrarily. Pipe functions are the | |
; usual sequence funcitons. (Hopefully) identical | |
; interface and behaviour. Laziness constraints | |
; apply. eg. for sort and reverse. | |
(def subpipe [(t/drop 100) (t/take 900000)]) | |
(def pipeline [(t/map inc) | |
(t/mapcat #(vector (* 2 %) (+ 5 %) (- % 100))) | |
t/subpipe | |
t/sort | |
t/dedupe | |
t/reverse | |
(t/filter even?)]) | |
(defn fast-vec-conj | |
([] (transient [])) | |
([v] (persistent! v)) | |
([v x] (conj! v x))) | |
; reduce | |
(t/transmute pipeline fast-vec-conj input) | |
; lazy | |
(t/sequence pipeline input) | |
; async | |
(let [inputc (async/chan) | |
outputc (at/chan inputc 0 pipeline)] | |
(async/go (async/onto-chan inputc input)) | |
(async/go-loop [] | |
(when-let [v (async/<! outputc)] | |
(print " -> ") | |
(prn v) | |
(recur)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment