Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Created April 16, 2014 10:07
Show Gist options
  • Save kurogelee/10846215 to your computer and use it in GitHub Desktop.
Save kurogelee/10846215 to your computer and use it in GitHub Desktop.
Clojureでwrite-lines関数を作ってみる ref: http://qiita.com/kurogelee/items/49de0428180675b505f7
(write-lines "sample.txt" ["あいう"] :encoding "Windows-31J")
(write-lines "sample2.txt" (range 10) :add-bom true :separator "x")
(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