Cleansing a Map of Its Channels

Viewed 133

Suppose we have a map m with the following structure:

{:a (go "a") 
  :b "b" 
  :c "c" 
  :d (go "d")}

As shown, m has four keys, two of which contain channels.

Question: How could one write a general function (or macro?) cleanse-map which takes a map like m and outputs its channeless version (which, in this case, would be {:a "a" :b "b" :c "c" :d "d"})?

A good helper function for this question might be as follows:

(defn chan? [c]
  (= (type (chan)) (type c)))

It also doesn't matter if the return value of cleanse-map (or whatever it's called) is itself a channel. i.e.:

`(cleanse-map m) ;=> (go {:a "a" :b "b" :c "c" :d "d"})
2 Answers
Related