Skip to content

Instantly share code, notes, and snippets.

@kotarak
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotarak/e400a31e6217bc9649ef to your computer and use it in GitHub Desktop.
Save kotarak/e400a31e6217bc9649ef to your computer and use it in GitHub Desktop.
(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