Fork me on GitHub

I have a nested structure and I want to filter out items based on a nested value in a collection

{:tag :a,
  :attrs {:href "",
          :name "adchoices_logo",
          :style "color:#000001;text-decoration:underline; height:13px; display:inline-block;",
          :target "_blank"},
  :content ({:tag :img,
             :attrs {:alt "AdChoices",
                     :border "0",
                     :src "",
                     :style "display:block;",
                     :title "AdChoices",
                     :width "69",
                     :height "15"},
             :content nil})}
In this case I want to filter out any items that have a :content value of nil


I've been attempting to use clojure.walk for this solution as it seems it would exhaust arbitrary depth, however, I'm at a loss for reconstructing the form


Talking to myself here but I think I figured it out, while also realizing I missed a key detail. nil is returned when a value is not preset in a hash for a given key. So, my "solution" works

(clojure.walk/prewalk #(filter (comp nil? :content) %) links)


but just returns a linked-list of empty linked-lists, as will all cases in this instance 😑 Sorry for the rudimentary question


'remove' is the analogous opposite to 'filter' if that helps.


what book would you recommend after reading Clojure for the Brave and True and Programming Clojure?


@rakyi I think The Joy of Clojure is very good


but it goes over some of the same material as the Brave and the True


that is the one I was thinking about as well


@rakyi Clojure Applied could be a nice read too.


will check it, thanks


@wds_: that's easy to do with specter

(def NODES (recursive-path [] p (continue-then-stay :content ALL p)))
(setval [NODES (selected? :content nil?)] NONE data)


I just stumbled on your talk about Specter this morning, beautiful library, thank you for assistance!


that will also be much higher performance than clojure.walk, since it's only traversing parts of your data structure that are relevant


clojure.walk will traverse into every key/value pair and map key


this behavior can also cause surprising bugs when parts of the data structure you weren't expecting are inadvertently affected


I'm trying to run:

(let [img (BufferedImage. 400 300 BufferedImage/TYPE_BYTE_GRAY)
      g2d (.getGraphics img)]
  (.drawString g2d "Hello World" 0 20)
  (ImageIO/write img "png" ( "out.png")))
on a headless jvm, and I get the error of: Could not initialize class sun.awt.X11GraphicsEnvironment

Alex Miller (Clojure team)16:03:57

use -Djava.awt.headless=true


Hi, I got surprised by this behavior of clojure.spec: ` (require ’[clojure.spec.alpha :as s]) (s/def :x/a integer?) (s/def :x/x integer?) (s/def :x/m (s/keys :req [:x/a])) (s/explain :x/m {:x/a 12, :x/x “invalid”}) => In: [:x/x] val: “invalid” fails spec: :x/x at: [:x/x] predicate: integer? ` I.e. when a map is validated, spec validates not only keys listed in the map’s spec (`:x/a`), but also keys that are not included but have their own spec defined (`:x/x`). What’s the rationale for that? And is there a way around it? How to say “Hey spec, validate only the keys I have mentioned explicitly in the map’s definition and ignore others”?

sundarj16:03:44 go to 46:00 to see Rich explaining this very thing

Alex Miller (Clojure team)16:03:31

and no, there is no way not to validate all attributes in keys


I'm using CLJ, not cljs. I need to read a json data in *.js file as a clojure map. Is the ideal library to use ?


data is small enough that it can all store in memory


data.json is OK, cheshire is good too


@qqq cheshire brings in more dependencies, but is substantially faster in most scenarios


I used data.json, turned out ot be fine, my data was only 84k


i wanted to throw this out there: one of the worst things about clojure is how well the language is designed. working in pretty much any other language really hammers-home the importance of syntax consistency, least-surprise, operator precedence, true/false consistency, polymorphic api design, etc.. it’s so painful to use anything else after clojure.


“clojure: making your job, where you cannot use it, more painful since 2009”


My (admittedly meager) experience is that fellow developers are far more conservative and resistant than managers.