This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-05
Channels
- # announcements (2)
- # babashka (9)
- # bangalore-clj (4)
- # beginners (20)
- # calva (5)
- # cider (1)
- # clara (2)
- # clojure (11)
- # clojure-italy (2)
- # clojure-spec (11)
- # clojure-uk (4)
- # clojurescript (34)
- # clojutre (7)
- # code-reviews (5)
- # cursive (3)
- # datascript (7)
- # fulcro (7)
- # graalvm (8)
- # jackdaw (1)
- # malli (1)
- # nrepl (4)
- # off-topic (225)
- # reagent (23)
- # reitit (14)
- # remote-jobs (1)
- # ring-swagger (1)
- # shadow-cljs (19)
- # tools-deps (10)
hey team im confused on this. when i get parameters from ring i get the following map {query test, tags [clojure something]}
and when i check this via an if statement i cannot do (if (contains? params :tags) true false)
but i can do (if (contains? params "tags") true false)
why is that?
@tjb It depends on the middleware you have in play
There is middleware that turns parameters into keywords
(`ring-middleware-keyword-params`)
awesome this is good info. thank you @U04V70XH6!
That's part of Ring core: https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/middleware/keyword_params.clj
hi guys, I'm trying to convert a string to a qualified keyword
"product-attribute/id-product-attribute" -> :product-attribute/id-product-attribute
I used (keyword)
but it only returns the keyword :id-product-attribute
I need the fully qualified ones, how can I achieve it?Maybe (apply keyword (clojure.string/split "product-attribute/id-product-attribute" #"/"))
thanks, I solved this way
(defn ->snake-case [s]
(let [ns (str/replace (namespace s) #"-" "_")
kw (str/replace (name s) #"-" "_")]
(keyword ns kw)))
but I have a feeling it might not be a good idea depending on why exactly you're doing this, and where exactly those strings come from.
next.jdbc returns the results with _ keywords instead of - , so I have to do a conversion in order to stay consistent and idiomatic
Use a builder function that does what you want @UJ9KCME4U That's the correct way to do it.
You probably want to add camel-snake-kebab as a dependency so you can use well tested functions
Questions about next.jdbc
are best asked in #sql to make sure I see them BTW
@U04V70XH6 thank you!!
is this binding (defn funcv [{:keys [db server-name]} token]...
takes token
and splits it into db
and server
name or something else happens?
it extracts the keys db
and server-name
from the first argument, where the first argument is a map: https://clojure.org/guides/destructuring#_associative_destructuring
I would have to noodle around at a REPL for a bit to confirm but I am pretty sure what you have there is a two-argument fn where the first arg is a map, from which you are pulling the :db
and :server-name
keys into symbols, and the second arg is something unspecified that you’re calling token
I suspect that what you want to do is: (defn funcv [{:keys [db server-name] :as token}] ...)
, which would take a single argument that is a map
, pull out :db
and :server-name
from that map as symbols, and also the entire map as token
for use elsewhere. The community-standard reference for the powerful, but complex, set of tools for destructuring stuff is here: https://gist.github.com/john2x/e1dca953548bfdfb9844