(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))))))))