Skip to content

Instantly share code, notes, and snippets.

@hiredman
Created March 7, 2010 04:31
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 hiredman/324145 to your computer and use it in GitHub Desktop.
Save hiredman/324145 to your computer and use it in GitHub Desktop.
(defn chunked-line-seq
"Returns the lines of text from rdr as a chunked[size] sequence of strings.
rdr must implement java.io.BufferedReader."
[#^java.io.BufferedReader rdr size]
(lazy-seq
(when-let [line (.readLine rdr)]
(chunk-cons
(let [chunk’ (chunk-buffer size)]
(chunk-append chunk’ line)
(dotimes [i (dec size)]
(when-let [line (.readLine rdr)]
(chunk-append chunk’ line)))
(chunk chunk’))
(chunked-line-seq rdr size)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment