Created
April 16, 2014 10:07
-
-
Save kurogelee/10846215 to your computer and use it in GitHub Desktop.
Clojureでwrite-lines関数を作ってみる ref: http://qiita.com/kurogelee/items/49de0428180675b505f7
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
(write-lines "sample.txt" ["あいう"] :encoding "Windows-31J") | |
(write-lines "sample2.txt" (range 10) :add-bom true :separator "x") |
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
(def line-separator (System/getProperty "line.separator")) | |
(defn write-lines | |
[f lines & {:keys [separator add-bom] | |
:or {separator line-separator add-bom false} :as opts}] | |
(with-open [^java.io.Writer w (apply clojure.java.io/writer f (apply concat opts))] | |
(when add-bom (.write w "\ufeff")) | |
(doseq [line lines] (.write w (str line separator))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment