Created
April 25, 2013 14:16
-
-
Save mnzk/5460035 to your computer and use it in GitHub Desktop.
固定文字数の文字列チャンクシーケンス作成関数(Clojure 1.5)
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 characters
(defn chunked-string-seq | |
([^java.io.Reader rdr] | |
(chunked-string-seq rdr :chunk-size 16)) | |
([^java.io.Reader rdr &{chunk-size :chunk-size}] | |
{:pre [(some-> chunk-size pos?)]} | |
(let [buf (char-array chunk-size)] | |
(letfn [(f [] | |
(when (pos? (.read rdr buf)) | |
(cons (String. buf) (lazy-seq (f)))))] | |
(f))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment