Hello, On Tuesday, March 4, 2014 10:47:12 PM UTC+1, Jason Felice wrote: > > Something like > > (with-open [rdr (clojure.java.io/reader "/dev/errors-sunday.csv")] > (->> (line-seq rdr) > (filter #(re-matches #"...")) > (map #(nth (string/split % #",") 1)))) > > Will do what you want. It's laziness to the rescue. >
Just a heads up: laziness is dangerous when using I/O. In this case, with-open will close the reader before all lines have been read, and throw an IOException for trying to read from a closed reader. Add a `doall` to the end of the threading, and it should be safe. Or use `slurp` to read the whole file, avoiding the problem to begin with. As another suggestion: You can use a for comprehension, if you consider it more readable. It's relatively similar to your imperative version. (with-open [rdr (clojure.java.io/reader "/dev/errors-sunday.csv")] (doall (for [line (line-seq rdr) :when (re-matches #"^[^,]+,[^,]+,FAIL,.*$" line)] (second (string/split line #","))))) -- Jean Niklas -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.