This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-11
Channels
- # aleph (1)
- # beginners (192)
- # boot (9)
- # cider (12)
- # cljs-dev (223)
- # clojure (30)
- # clojure-brasil (3)
- # clojure-china (1)
- # clojure-italy (4)
- # clojure-russia (24)
- # clojure-spec (7)
- # clojured (5)
- # clojurescript (82)
- # cursive (9)
- # datomic (24)
- # emacs (6)
- # fulcro (9)
- # keechma (1)
- # luminus (1)
- # off-topic (3)
- # om-next (5)
- # onyx (1)
- # parinfer (9)
- # re-frame (1)
- # reitit (4)
- # ring-swagger (6)
- # shadow-cljs (8)
- # spacemacs (1)
- # sql (1)
- # unrepl (13)
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
what book would you recommend after reading Clojure for the Brave and True and Programming Clojure?
@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.X11GraphicsEnvironmentuse -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â?
https://vimeo.com/195711510 go to 46:00 to see Rich explaining this very thing
I have to run but https://clojure.org/about/spec
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 https://github.com/clojure/data.json the ideal library to use ?
data.json is OK, cheshire is good too
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.