(defn
keep
"Returns a lazy sequence of the non-nil results of (f item). Note,\n this means false return values will be included. f must be free of\n side-effects. Returns a transducer when no collection is provided."
([f]
(fn
[rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(let [v (f input)] (if (nil? v) result (rf result v)))))))
([f coll]
(lazy-seq
(when-let
[s (seq coll)]
(if
(chunked-seq? s)
(let
[c (chunk-first s) size (count c) b (chunk-buffer size)]
(dotimes
[i size]
(let [x (f (-nth c i))] (when-not (nil? x) (chunk-append b x))))
(chunk-cons (chunk b) (keep f (chunk-rest s))))
(let
[x (f (first s))]
(if (nil? x) (keep f (rest s)) (cons x (keep f (rest s))))))))))