May 2018
Beginner to intermediate
290 pages
6h 43m
English
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 ...
Read now
Unlock full access