1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Clojure with-in-str と with-out-str の使い方

Posted at

Ruby でいう StringIO みたいなもの。標準入力 *in* と標準出力 *out* をスタブしてくれる感じの便利関数。

どちらも標準入出力を扱う処理のテストに便利そう。あと暗黙に標準出力に書く関数を with-out-str でラップして出力をインターセプトし文字列として何か他のことに利用する、などのテクニックも使いたくなることがありそう。

ドキュメント

コードスニペット

(ns clj-with-in-str.core)

(read-line)

(with-in-str "Hello world"
  (read-line))

(with-in-str "Hello world"
  (slurp *in*))
(ns clj-with-out-str.core)

(println "Hello world")

(with-out-str
  (println "Hello world"))
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?