Skip to content

Instantly share code, notes, and snippets.

@denlab
Last active December 14, 2015 09:19
Show Gist options
  • Save denlab/5064179 to your computer and use it in GitHub Desktop.
Save denlab/5064179 to your computer and use it in GitHub Desktop.
(clojure.string/split (slurp "my.file") #"\e")
(-> "my.file"
slurp
(clojure.string/split #"\e"))
(-> "my.file"
slurp
(clojure.string/split #"\e")
(filter #(re-find #"foo" %))
clojure.repl/pprint)
(defn char-seq
"Returns a lazy-seq of char from rdr.
Note: Adapted from clojure.core/line-seq"
[rdr] (let [c (.read rdr)]
(when (not= -1 c)
(cons (char c) (lazy-seq (char-seq rdr))))))
(defn line-seq+
"Like clojure.core/line-seq but the line separator is customizable."
[rdr line-sep]
(->> rdr
char-seq
(partition-by ∈{line-sep})
(remove ∈{[line-sep]})
(map #(reduce str %))))
(comment "example:"
(line-seq+ (io/reader (io/file "my.file")) \e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment