clojure.core/line-seq¶
Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader.
Examples¶
Note by nxtk¶
Documentation says that line-seq returns a lazy sequence, however
the actual return value is a Cons cell of the first line to a LazySeq of
the second line. Calling realized? on the Cons cell will fail with an exception.
(cons (.readLine rdr) (lazy-seq (line-seq rdr)))
Example:
(def rdr (BufferedReader. (StringReader. " 1\n 2\n 3")))
(def x (line-seq rdr))
(class x)
=> clojure.lang.Cons
(realized? x)
=> Execution error (ClassCastException) class clojure.lang.Cons cannot be cast to class clojure.lang.IPending
The first line was eagerly realized by the initial call to the line-seq.
(.readLine rdr)
=> " 2"
See also¶
Content from the matching ClojureDocs page, with authors credited on each contribution.