Debugging Usages of the Thrush Operator

Thursday, July 14, 2011 12:01 PM

Creating long chains of transformation using the thrush operator looks attractive, but what if you need to see what it's doing?

Consider the following code:

(-> 1  
  inc
  inc)

Now it's obvious that this returns 3, and that the intermediate value was 2, but the following code proves it:

(defn thread-println [v prefix]  
  (doto v (->> (str prefix) println))) (-> 1
  inc
  (thread-println "Intermediate value was")
  inc)

You'd need to write a second function for ->>, sadly.

Technorati Tags: ,
Comments
No comments posted yet.
Something to add?

Talking sense? Talking rubbish? Something I'm missing? Let me know!

Fields denoted with a "*" are required.

 (will not be displayed)

 
Please add 7 and 1 and type the answer here:

Preview Your Comment