Skip to content

Instantly share code, notes, and snippets.

@fbmnds
Last active December 19, 2015 14:19
Show Gist options
  • Select an option

  • Save fbmnds/5968844 to your computer and use it in GitHub Desktop.

Select an option

Save fbmnds/5968844 to your computer and use it in GitHub Desktop.
Explicite iteration on CLR
(require '[clojure.clr.io :as io])
(def in-file "/path/to/datafile-4gb.tsv")
(def out-file "/path/to/datafile-16gb.tsv")
(defn multiply-string [s n]
(cond
(> n 1) (str s \newline (multiply-string s (dec n)))
(= n 1) (str s \newline)
:else nil))
(defn multiply-file [in out n]
(with-open [reader (io/text-reader in) ; FB: io/reader
writer (io/text-writer out)] ; FB: io/writer
(loop [line (.ReadLine reader)] ; FB: .readLine
(if (nil? line)
nil
(do
(.Write writer (multiply-string line n)) ; FB: .write
(recur (.ReadLine reader))))))) ; FB: .readLine
#'user/multiply-file
user=> (time (multiply-file in-file out-file 4))
"Elapsed time: 2638910 msecs"
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment