Fork me on GitHub
Rob Haisfield00:07:31

Awesome, thank you @smith.adriane for the helpful explanations. That cleared up a lot for me

👍 3
Rob Haisfield00:07:31

Is there equivalent to contains? for finding if a value is present in a map?

contains? Returns true if key is present in the given collection, otherwise
returns false.


You can also use Java interop for this:

(.containsValue {:a 1} 1)
;> true
But this won't be portable to other Clojure dialects, like it won't work in ClojureScript. If you want something portable, better stick to using some.

Rob Haisfield00:07:16


(value-contains? {:a 1} 1) => true


I'd probably use something like (some (comp #{1} val) the-map)

🚀 3

user=> (def the-map {:a 1 :b 2})
user=> (some (comp #{1} val) the-map)
user=> (some (comp #{2} val) the-map)
user=> (some (comp #{3} val) the-map)


if you need more than true/false, can use medley.core. see filter-vals,


why is this test failing :

(def __ '(5 2 4))

   [2 5 4 1 3 6]
   (drop 2)
   (take 3)
   (map inc))

 (__ (map inc (take 3 (drop 2 [2 5 4 1 3 6])))) := (->> [2 5 4 1 3 6] (drop 2) (take 3) (map inc) (__)))

Geoffrey Gaillard08:07:10

It seems you are calling as a function with ()


you mean the answer is only 5 2 4 without the parentheses ?

Geoffrey Gaillard08:07:35

is a value. You could try (map inc (take 3 (drop 2 [2 5 4 1 3 6])))) :=

Geoffrey Gaillard08:07:36

'(5 2 4) is a list. So calling it like () is equivalent to ('(5 2 4)), meaning "call this list as a function", which fails.


so the answer needs to be onky 5 2 4


({:xAxisValue "MAR 2017", :yAxisValue "NA", :clientYAxisValue 2, :client10p 0, :client90p 0 :shareYAxisValue 6, :share10p 1, :share90p 1}
           {:xAxisValue "APR 2017", :yAxisValue 1, :clientYAxisValue 4, :client10p 0, :client90p 0 :shareYAxisValue 7, :share10p 1, :share90p 1}
           {:xAxisValue "MAY 2017", :yAxisValue 2, :clientYAxisValue 5, :client10p 0, :client90p 0 :shareYAxisValue 8, :share10p 1, :share90p 1}
           {:xAxisValue "JUNE 2017", :yAxisValue 5, :clientYAxisValue "NA", :client10p "NA", :client90p "NA" :shareYAxisValue "NA", :share10p "NA", :share90p "NA"})


user=> (def a '({:x 1 :y 1} {:x 2 :y 2}))
user=> (def b '({:x 1 :z 1} {:x 2 :z 2}))
user=> (map #(apply merge %) (vals (group-by :x (concat a b))))
({:x 1, :y 1, :z 1} {:x 2, :y 2, :z 2})


Hey, could someone help me to configure emacs+cider pprint? I'm currently facing the problem that my emacs freezes when I try to pprint a long string. I tried (setq cider-print-options '(("length" 50) ("right-margin" 70))) but this does not resolve the issue (or I'm missing something)


Hello, may I know if a Ring server automatically handles multiple requests? o:


Yup, ring’s default jetty web server and most others will have a thread pool to handle concurrent requests. Ring itself though is more like a pattern for working requests at the application level.


Hello, I've set up an http-kit server on localhost:3000 which I'm trying to call from a cljs app on 9090, but I keep getting a Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at . (Reason: CORS header 'Access-Control-Allow-Origin' missing). I have ring-cors set up, but it doesn't look to me like the "Allow" header is being populated. My app looks like this:

(def app
  (-> #'routes
      (wrap-defaults site-defaults)
      (wrap-cors :access-control-allow-credentials "true"
                 :access-control-allow-origin [#""])))
Full file curl --head localhost:3000 gives the following, also missing the origin allow
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: ring-session=64c4da9f-5dd2-4b62-9ae6-d1eff297d835;Path=/;HttpOnly;SameSite=Strict
X-Xss-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Content-Length: 0
Server: http-kit
Date: Sun, 25 Jul 2021 15:16:18 GMT
am I not using the wrap-cors correctly? Thanks!


Thanks Cora, I made the change (silly typo), but no dice unfortunately. To be clear, the curl works fine, and returns as I expect it to, just missing the allow header. It's only when I hit it from the browser that it doesn't work.


▶ curl -X OPTIONS localhost:3000 -i    
HTTP/1.1 404 Not Found
Content-Length: 0
Server: http-kit
Date: Sun, 25 Jul 2021 15:48:28 GMT
▶ curl  localhost:3000 -i          
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: ring-session=6b7042cf-4a86-484c-bac2-13a0217f349e;Path=/;HttpOnly;SameSite=Strict
X-Xss-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Content-Length: 17
Server: http-kit
Date: Sun, 25 Jul 2021 15:48:58 GMT


Cora (she/her)15:07:19

if you want to test it with curl you need to send the requests like your browser does. your browser sends a preflight request

Cora (she/her)16:07:05

you can inspect the network tab in your inspector in your browser to confirm it is sending these requests and to see what response you're getting

Cora (she/her)16:07:04

a preflight request is where you'll see the headers you set in the cors middleware


I see, thanks - I guess I need to read more about the preflight request and how they work

Cora (she/her)16:07:21

it's good stuff to know!

👍 3
Karol Wójcik16:07:02

Curl will probably always work for preflight

Cora (she/her)17:07:57

is there a way to set a browser context in curl to make preflight make sense? because you'd need to set the current origin so that it knows to do a CORS preflight when you request a different origin and can check the preflight response to make sure the CORS request is allowed for the current browser context

Cora (she/her)17:07:34

I mean you could just send the preflight request yourself with the Origin header and the Access-Control-Request-Method header but that's not really automatic


Maybe a late answer... but I had this problem... and after much searching ... I figured out that in the service settings I needed to have ::http/secure-headers {:content-security-policy-settings {:object-src "none"}} as one of the entries... This is for my pedestal server setup tho... so keep that in mind!! Happy Clojuring!!


Thanks ChillPillzKillzBillz, I'll give that a go.

Cora (she/her)15:07:53

also try making the curl using -X OPTIONS instead of --head

Samuel Couto19:07:22

Hello, how a LocalDateTime is declared using spec-tools?

Cora (she/her)19:07:26

would inst? work there?

Cora (she/her)19:07:43

doesn't seem like it

Cora (she/her)19:07:02

user=> (s/def ::local-date-time #(instance? LocalDateTime %))
user=> (s/valid? ::local-date-time 1)
user=> (s/valid? ::local-date-time (LocalDateTime/now))

Cora (she/her)19:07:10

@samuel.couto92 that seems to work for me? ^

Samuel Couto20:07:31

It works, thanks 😄

Cora (she/her)19:07:16

so you'd put :startDateTime ::local-date-time I guess


If I have an s-expression with metadata that includes line+col information, is there any built in function that can either print out that s-expression putting in line breaks as appropriate? (Alternatively converting the s-expression to a string works.)


Im not sure if there is something taking into account the metadata but for printing human readable s-expressions there is


@U6JS7B99S Does pprint print things out in a way that can be read back in with, say read-string?


I believe that there are cases where it doesn't - for example printing a java class instance. It also cannot read back in record instances (It would read them as plain maps)


As far as EDN-ready values go it should, I believe, be possible


Which is about what I would expect from pr and prn.


Still sad that it will reflow everything, but I guess it can't be helped. Thanks.


you may be interested in something like which can read edn and preserve whitespace.


Basically, looking for something machine readable, but with human-readable spacing.


How would you summon the find-versions tool talked about I'm trying clj -X:deps find-versions :lib io.github.clojure/tools.deps.graph and all I get is the error message Function not found:


What version of the clojure cli are you using ?


Is that the prerelease version? The new goodies haven’t made it into a stable release yet


ohhhhh probably not.


weird that it would already be in the official docs...

Cora (she/her)21:07:53

was going to suggest asking in #tools-deps but @seancorfield is typing


@cdimara I think Alex was hoping to get to a stable release faster -- but there have been a number of bug fixes on the prerelease side and the Windows scripts also needed to be substantially updated.


(I suspect he also hoped folks read the news article about the changes -- -- where it mentions the prerelease... but it certainly has caused some confusion for quite a few folks based on the Qs I've seen posted here in various channels and on ClojureVerse)


The latest prerelease is I believe (we're on at work). You can see all the release numbers here but only stable releases are listed here (and I don't think anyone would expect folks generally to tie Clojure CLI to brew-install when trying to figure that out, which is why I'm linking to it).


Oh man I totally read that article. And I assumed it was about features in a current release. Glazed right over the installation part. sorry.


Easy to miss: it's only mentioned on one line over halfway through the article I think...

Cora (she/her)21:07:59

it's hard to know what to call out and how to do it

Cora (she/her)21:07:05

writing is hard

Cora (she/her)21:07:55

and then you think "I have sufficiently called this out, this is good" and yet somehow our ape brains still defy all our best efforts

Cora (she/her)21:07:16

cruel defiers of efforts that they are


I'll make the same offer here that I've made in a few other threads: my DMs are always open for any Qs about the Clojure CLI, tools.deps,, and stuff like clj-new, depstar, etc 🙂 (which will make sure I see the Q, whereas I might miss it here)

thanks3 6
👍 2

A lot of deps.edn tooling out there still assumes -A as the way to invoke things (despite how long there has been a warning to use -M instead) and a lot of people are still using old CLI installs that don't support -X so that also adds to the confusion (in the opposite direction).


(and the behavior of -M changed so old CLI versions don't get the warning for using -A but can't actually use -M because it hadn't used to pick up dependencies!)