One of the nice features about Clojure is that most of its sequence processing functions are lazy. This allows us to handle very large datasets with very little effort. However, when combined with reading from files and other IO, there are several things to watch out for.
In this recipe, we'll look at several ways of safely and lazily reading a CSV file. By default, clojure.data.csv/read-csv
is lazy, so how do we maintain that feature while closing the file at just the right time?
We need to load the libraries we're going to use into the REPL. This can be done using the following instructions:
(require '[clojure.data.csv :as csv] '[clojure.java.io :as io])