Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. (defn- split-lines
  2. "Takes a sequence of content chunks and returns a lazy sequence of individual lines.
  3. (\"abc\" \"de\\nabc\") becomes (\"abcde\" \"abc\")"
  4. [stream]
  5. (let [
  6. chunk (first stream)
  7. remainder (rest stream)
  8. [line leftover] (string/split chunk #"\n+" 2)]
  9. (if leftover
  10. (lazy-seq (cons line (split-lines (cons leftover remainder))))
  11. (recur (cons
  12. (string/join "" (cons line (first remainder)))
  13. (rest remainder))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement