Fork me on GitHub
#clojure
<
2023-03-23
>
jdkealy00:03:39

Is there a way to safely look up some crazy nested structure like this without having to be overly verbose ? (first (vals (first (vals (ffirst (vals (:_source (first (:hits (:hits (:display val))))))))))

jdkealy00:03:43

Somehting instead of having to do

(if 
  (and 
     (:display val) 
     (:hits (:display val)) 
     (:hits (:hits (:display val))
    (first (:hits (:hits (:display val))))

hifumi12300:03:13

I would guess

(some-> val :display :hits ... first)

hifumi12300:03:23

this will short circuit on the first nil value

馃憤 2
jdkealy00:03:33

Awesome I had no idea !

jdkealy00:03:36

Thanks

馃憤 2
Mario Trost11:03:24

Back then I tried to solve the question with for (I wasn't the OP there), but couldn't and left it. After seeing the same answer again I searched for other times when @U0NCTKEV8 answered with "use for" and I found one occurrence from 2017, and some posts farther down this example, in case any other beginner's curious what "use for" looks like in practice (but was a different problem than the OP asked here): https://clojurians.slack.com/archives/C03S1KBA2/p1509568612000206

DrLj贸tsson22:03:51

I am new to deps.edn , how do I find out what library includes a transitive dependency? Specifically, I want to find out what library/ies include/s ch.qos.logback/logback-core

dorab22:03:29

Try clj -Stree in the project directory.

DrLj贸tsson22:03:33

Thanks! I found it and it is a transitive dependency at least a couple of libraries "down".

luminus-immutant/luminus-immutant 0.2.5
  . org.immutant/web 2.1.10
    . org.immutant/core 2.1.10
      . org.clojure/java.classpath 0.2.3
      X org.clojure/tools.reader 0.10.0 :use-top
      . org.projectodd.wunderboss/wunderboss-clojure 0.13.1
    . org.projectodd.wunderboss/wunderboss-web-undertow 0.13.1
      . org.projectodd.wunderboss/wunderboss-core 0.13.1
        . ch.qos.logback/logback-classic 1.1.3
          . ch.qos.logback/logback-core 1.1.3
Do I need to manually include the innermost including library and exclude logback-classic from that to get rid of the dependency? I guess that would be org.projectodd.wunderboss/wunderboss-core

Alex Miller (Clojure team)22:03:26

no, you can add an exclusion in luminus-immutant/luminus-immutant of ch.qos.logback/logback-classic

Alex Miller (Clojure team)22:03:43

luminus-immutant/luminus-immutant {:mvn/version "0.2.5" :exclusions [ch.qos.logback/logback-classic]}

Alex Miller (Clojure team)22:03:56

that will exclude logback-classic, and it's dependency logback-core