Other Sources of Sequences

Given all the leverage you can get out of sequences, it’s not surprising that you can turn lots of things besides maps, vectors, and lists into sequences. The line-seq function, for example, will turn the contents of a text file into a sequence. So if we had all our authors’ names in a file called authors.txt, we could write a function to determine if an author is listed:

 (require '[clojure.java.io :as io])
 
 (​defn​ listed-author? [author]
  (with-open [r (io/reader ​"authors.txt"​)]
  (some (partial = author) (line-seq r))))

Let’s put aside the require and with-open (it opens and closes a file) expressions for the moment and focus on the last line. In that last line we use line-seq to turn the contents of the ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.