Created
March 11, 2012 07:13
-
-
Save bmmoore/2015393 to your computer and use it in GitHub Desktop.
Revisions
-
bmmoore created this gist
Mar 11, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ (defn repeated-until* [element done] (reify Reader (read-bytes [this b] (loop [b b, result []] (let [[success x b] (read-bytes element b)] (if success (if (= x done) [true result b] (recur b (conj result x))) [false (compose-callback this (fn [result2 b2] [true (concat result result2) b2])) b])))) Writer (sizeof [_] nil) (write-bytes [_ buf vs] ;; should perhaps do something smarter if size fixed. (loop [chunks [], items vs] (if-let [elt (first items)] (recur (conj chunks (write-bytes element buf elt)) (rest items)) (concat (conj chunks (write-bytes element buf done))))))))