Skip to content

Instantly share code, notes, and snippets.

@bmmoore
Created March 11, 2012 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmmoore/2015393 to your computer and use it in GitHub Desktop.
Save bmmoore/2015393 to your computer and use it in GitHub Desktop.
repeated-until, directly
(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))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment