This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-26
Channels
- # admin-announcements (1)
- # beginners (12)
- # cider (2)
- # cljs-dev (6)
- # cljsrn (4)
- # clojure (123)
- # clojure-austin (10)
- # clojure-brasil (1)
- # clojure-canada (21)
- # clojure-conj (5)
- # clojure-dev (8)
- # clojure-gamedev (42)
- # clojure-russia (121)
- # clojure-sanfrancisco (2)
- # clojure-spec (25)
- # clojure-uk (36)
- # clojurescript (195)
- # clojutre (3)
- # cursive (43)
- # datomic (6)
- # defnpodcast (2)
- # dirac (14)
- # emacs (2)
- # ethereum (2)
- # events (2)
- # funcool (6)
- # hoplon (76)
- # jobs (1)
- # kekkonen (9)
- # lein-figwheel (1)
- # leiningen (4)
- # mount (6)
- # off-topic (5)
- # om (2)
- # onyx (91)
- # pedestal (2)
- # protorepl (14)
- # re-frame (22)
- # reagent (20)
- # rethinkdb (1)
- # ring (2)
- # schema (3)
- # sfcljs (3)
- # spacemacs (15)
- # specter (12)
- # testing (1)
- # yada (63)
Does anyone know of an easy way to use a String as a Reader, without resorting to Java?
I’m writing test code and it just seems a bit ugly to have to manually create StringWriter and StringReader instances.
I could use with-out-str
and send output to *out*
- but I’m not keen on that approach, it’s too easy for other stuff to go to out by accident
(with-open [s-in (
would do as an InputStrem if that is not a problem korny
Just to clarify, my test looks like:
(let [in (StringReader. simple-sample)
out (StringWriter.)]
(subject/convert-yaml-to-csv in out)
out)
=> … expected result …
So it’s not that complex. Just hoping for something more clojure-y than explicitly using StringReader and StringWriter
(really, my convert-yaml-to-csv
should take a sequence of strings and return a sequence of strings, which would be more cleanly testable, and then wrap that in a function that uses readers and writers)
wrapping that pattern up in a helper function is probably as nice as you’re likely to get
yeah - I could clone with-out-str
- it’s fairly simple:
(defmacro with-out-str
"Evaluates exprs in a context in which *out* is bound to a fresh
StringWriter. Returns the string created by any nested printing
calls."
{:added "1.0"}
[& body]
`(let [s# (new java.io.StringWriter)]
(binding [*out* s#]
~@body
(str s#))))
I love the smell of a macro in the morning....
Someone should make a meme with Aphyr’s face and a “Yo dawg - I heard you like macros…” byline.
A plug for a funky one day conference... https://juxt.pro/blog/posts/XT16-programme.html
@jonpither Axe Throwing?
I didn’t know that. I guess it’s hard to find lawyers when you (allegedly) killed your wife and hid the body
We're trying to do the ax throwing and yukes in different areas.