Fork me on GitHub

I’m constantly amazed by the answers i see on 4clojure.

(fn [& sets]
  (let [p-set (fn [ss] (->> (map (fn [v] #(->> v (conj %2) (conj %1))) ss)
                            (reduce #(reduce %2 %1 %1) #{#{}})))]
    (->> (map p-set sets)
         (map #(disj % #{}))
         (map #(map (partial apply +) %))
         (map set)
         (apply clojure.set/intersection)
         (empty?) (not))))
That one is a bit of a head scratcher, but at least i see what the confusing part is doing. With some answers i dont know where to start. I think maybe in browser answers might not have produced the most readable code. At least i hope thats the reason i can’t read some of these -_-.


For me, one advantage of this dense clojure code over other languages I have worked on in the past is that I can comment out some part of it and the code is still runnable. What I normally do when I got this chuck of code snippet that I don’t understand what it’s doing is to set this up in my editor with connected repl. Then I comment out most of the lines except the first one (In this case, (->> (map p-set sets))). Evaluate it to see the result in the repl. Trying to understand it, uncommment the next line, eval it, try to understand it and repeat until it’s all uncommented.


I think it requires a bit of behavior change to always keep in mind that I now have the repl close to my hand. It’s so easy to run a code snippet especially when there’s no external dependencies or side-effects. I don’t have to fully rely on my brain to compute the whole code snippet anymore


Is there an idiomatic way to print a value in a threading macro (`->` or ->>) and then return the identity? Of course I can defn my own function, but I think I saw something clever once and forgot it...


with -> doto kind of works


I think I had something else in mind but that is good to know already!


another approach is

(-> x (f) (g) (as-> % (do (println "foo:" %) %)) (h))