Tap support playground

We have recently added Clojure tap support to Nextjournal. The most simple case is as follows:

(tap> :hello_tap)
(println "hello_print")
0.7s
Clojure
:hello_tap
nil

Values send via tap are displayed above the result and below the stdout of a cell. One can now use our viewer API to send asynchronous updates during an execution.

(tap> {:nextjournal/viewer :html
       :nextjournal/tap-id :foo
       :nextjournal.viewer/value
       (str "<pre>" "Progress bar:" (apply str (repeat 3 "πŸ˜ƒ")) "</pre>")})
0.1s
Clojure
Progress bar:πŸ˜ƒπŸ˜ƒπŸ˜ƒπŸ˜ƒπŸ˜ƒ
true

The optional :nextjournal/tap-id identifies a tap output which one can update also in other cells. Specifying a tap-id is like a database upsert operation. If the id exists the tap output gets updated, if it doesn't exist the new output gets appended to the tap section of the current cell. With no tap-id specified the result gets pushed to the tap section of the executing cell.

(tap> {:nextjournal/viewer :html
       :nextjournal/tap-id :foo
       :nextjournal.viewer/value
       (str "<pre>" "Progress bar:" (apply str (repeat 5 "πŸ˜ƒ")) "</pre>")})
0.0s
Clojure
true

One use case is to implement a progress bar.

(for [i (range 10)]
  (do (Thread/sleep 1000)
    (tap> {:nextjournal/viewer :html
           :nextjournal/tap-id :bar
           :nextjournal.viewer/value
           (str "<pre>" "Progress bar: " 
                (apply str (repeat (inc i) "πŸ˜ƒ")) "</pre>")})))
10.2s
Clojure
Progress bar: 😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍
List(10) (true, true, true, true, true, true, true, true, true, true)

The tap-id can also be specified via metadata.

(tap> ^{:nextjournal/tap-id :bar}
      {:nextjournal/viewer :html
       :nextjournal.viewer/value
       (str "<pre>" "Progress bar: " 
            (apply str (repeat 20 "😍")) "</pre>")})
0.0s
Clojure
true

Also check out playing Tic Tac Toe on Nextjournal!

Runtimes (1)