Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Clojure IO Protocols
(defprotocol IO
"A protocol for reading and writing"
(read-file [this])
(write-file [this]))
(extend-protocol IO
(read-file [file]
(with-open [rdr ( file)]
(reduce conj [] (line-seq rdr))))
(write-file [text dest & opts]
(with-open [w ( dest ~@opts)]
(.write w text))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.