Last active
May 6, 2017 18:31
-
-
Save kellegous/8fa436166fc296e575e3a2a3b49777ad 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
(ns playsync.core | |
(:require [clojure.core.async | |
:as a | |
:refer [>! <! >!! <!! go chan buffer close! thread | |
alts! alts!! timeout]])) | |
(defn pipe-through | |
[f in out] | |
(go (>! out (f (<! in))))) | |
(defn pipeline-of | |
[& stages] | |
(let [first-chan (chan)] | |
(loop [first-chan first-chan in first-chan stages stages] | |
(if (empty? stages) | |
#(do | |
(go (>! first-chan %)) | |
(<!! in)) | |
(let [out (chan)] | |
(pipe-through (first stages) in out) | |
(recur first-chan out (rest stages))))))) | |
(defn -add | |
[a b] | |
((apply pipeline-of (repeat a inc)) b)) | |
(def add (memoize -add)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment