Debugging Usages of the Thrush Operator

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: ,

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s