title: More idiomatic line-by-line handling of a file in Clojure
body: <p>I'm trying to read a file that (may or may not) have <a href="http://jekyllrb.com/docs/frontmatter/" rel="nofollow">YAML frontmatter</a> line-by-line using Clojure, and return a hashmap with two vectors, one containing the frontmatter lines and one containing everything else (i.e., the body). </p>
  
  <p>And example input file would look like this:</p>
  
  <pre><code>---
  key1: value1
  key2: value2
  ---
  
  Body text paragraph 1
  
  Body text paragraph 2
  
  Body text paragraph 3
  </code></pre>
  
  <p>I have functioning code that does this, but to my (admittedly inexperienced with Clojure) nose, it reeks of code smell.</p>
  
  <pre><code>(defn process-file [f]
    (with-open [rdr (java.io.BufferedReader. (java.io.FileReader. f))]
      (loop [lines (line-seq rdr) in-fm 0 frontmatter [] body []]
        (if-not (empty? lines)
          (let [line (string/trim (first lines))]
            (cond
              (zero? (count line))
                (recur (rest lines) in-fm frontmatter body)
              (and (&lt; in-fm 2) (= line "---")) 
                (recur (rest lines) (inc in-fm) frontmatter body)
              (= in-fm 1)  
                (recur (rest lines) in-fm (conj frontmatter line) body)
              :else          
               (recur (rest lines) in-fm frontmatter (conj body line))))
          (hash-map :frontmatter frontmatter :body body)))))
  </code></pre>
  
  <p>Can someone point me to a more elegant way to do this? I'm going to be doing a decent amount of line-by-line parsing in this project, and I'd like a more idiomatic way of going about it if possible.</p>