Available for hire
How to Read a File Using Clojure

Today I needed to read a small file into a vector so I can iterate over it line by line. Here is the small function to do this.

1
2
3
4
(defn read-file [f]
  "Read in a file and return the result"
  (-> (slurp f)
    (clojure.string/split #"\n")))

And then to use

1
(println (read-file "resources/input.txt"))

Comments