(doto println)
is very useful in a
(-> x)
A few days ago, I learned that you can partially evaluate clojure threads in the repl. :chefskiss: Am i rite?
Today, that same slack thread includes a tip for solving another annoying issue - quickly printing that partial value.
In the past I've created annoying verbose anon funcs to print or def the val
while it's passing through
(-> 2
(+ 2)
((fn [x] (prn x) x)) ;; <----- so many parens just to print this thing
(->> (/ 84))
#_ ...etc)
Enter
doto
:
(-> 2
(doto prn) ;; => 2
(->> (/ 84)
(doto prn) ;; => 42
(as-> % (< 40 % 50))
(doto prn)) ;; => true
This
doto
usage is much nicer! Level up!
---
Worth noting:
doto
is a "threading" macro, like
->
and
->>
.
Its args:
[x & forms]
It passes
x
as the first argument to all the
forms
.
(-> *file*
(doto
println ((fn [x] (println x))) (str "<-- your file was here,
but this string was thrown away, b/c it has no side-effects. ")))
questionable copy-pasta - i think things just moved to xdg config style
bbin install examples
awesome talk covering prototypes for sketching/drawing combined with programming
https://www.youtube.com/watch?v=ifYuvgXZ108&list=PLcGKfGEEONaDO2dvGEdodnqG5cSnZ96W1&index=5
see also:
not to be confused with: