1.3.0 permalink Arrow_down_16x16

line-seq

clojure.core

  • (line-seq rdr)
Returns the lines of text from rdr as a lazy sequence of strings.
rdr must implement java.io.BufferedReader.

2 Examples top

  • ;; Count lines of a file (loses head):
    user=> (with-open [rdr (clojure.java.io/reader "/etc/passwd")]
             (count (line-seq rdr)))
    
    
  • (import '(java.io BufferedReader StringReader))
    
    ;; line terminators are stripped
    user=> (line-seq (BufferedReader. (StringReader. "1\n2\n\n3")))
    ("1" "2" "" "3")
    
    ;; empty string gives nil
    user=> (line-seq (BufferedReader. (StringReader. "")))
    nil
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2670 top

(defn line-seq
  "Returns the lines of text from rdr as a lazy sequence of strings.
  rdr must implement java.io.BufferedReader."
  {:added "1.0"
   :static true}
  [^java.io.BufferedReader rdr]
  (when-let [line (.readLine rdr)]
    (cons line (lazy-seq (line-seq rdr)))))
Vars in clojure.core/line-seq:
Used in 0 other vars

Comments top

No comments for line-seq. Log in to add a comment.