This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-13
Channels
- # aleph (8)
- # announcements (3)
- # beginners (36)
- # calva (1)
- # cider (1)
- # circleci (3)
- # clj-kondo (9)
- # cljdoc (58)
- # clojars (7)
- # clojure (70)
- # clojure-europe (13)
- # clojure-japan (1)
- # clojure-nl (8)
- # clojure-russia (2)
- # clojure-uk (7)
- # clojuredesign-podcast (4)
- # clojurescript (67)
- # clojureverse-ops (14)
- # cursive (6)
- # data-science (1)
- # datahike (3)
- # datomic (6)
- # docker (1)
- # events (2)
- # figwheel-main (9)
- # fulcro (4)
- # graalvm (33)
- # graphql (8)
- # helix (1)
- # jobs (1)
- # leiningen (3)
- # lsp (39)
- # malli (9)
- # minecraft (31)
- # nextjournal (7)
- # off-topic (6)
- # portal (22)
- # re-frame (5)
- # reitit (5)
- # remote-jobs (1)
- # shadow-cljs (55)
- # sql (22)
- # tools-build (3)
- # tools-deps (4)
- # xtdb (6)
Hi guys. Did anybody meet a problem like this? I use shadow-cljs with react-native and try to set up a project from scratch as mentioned here https://github.com/thheller/reagent-react-native but stuck with that error.
How do I add multiple maps like this
{:vehicle "default"
:service "default"
:config "my-config"
:country "default"
:value 2500}
at once to a list which already has maps of this typeThe different functions cater to slightly different needs: some allow for appending multiple items in one go versus just adding one item, into
preserves the type of the target collection,...
Do you have a list of maps
(A B C)
where the maps A, B and C looks like what you described above? And you want to add more maps D, E and F to this list?Then you can use (into '(A B C) '(D E F))
, which will return the list '(F E D A B C)
, or replace into
with concat
, which will return '(A B C D E F)
. The reason these two give different results is that into
takes elements from the second list one at a time and adds it to the first one, each time placing that element at the front of the list, while concat
just concatenates them together.
hi everyone how this code may be rewritten in clojure way correctly?
(if smth
(do smth
return smth)
(if smth2
(do smth
return smth)
(if smth3
….)
I’ve tried (some->> args fn1 fn1)
but it doesn’t fir here because I don’t understand how to pass few arguments as list, and I need to return smth
in if leaf. I understand that there is no returns but still )What are you trying to achieve? If either smth
, smth2
or smth3
are true, then evaluate smth
?
sorry about confusing code) is other languages it will be simple if sequence
if a is None and b is None:
# do somthing and
return map[]
elif a is not None and b is None:
# do somthing and
return map[]
elif a is None and b is not None:
# do somthing and
return map[]
else:
# do somthing and
return map[]
you can use a cond for that, just a sec
(cond
(and (not a) (not b))
(do
;; some processing
return-value1)
(and a (not b))
(do
;; some processing
return-value2)
(and (not a) b)
(do
;; some processing
return-value3)
:else
(do
;; some processing
return-value4))
cf https://clojuredocs.org/clojure.core/condWhen dealing with a lot of map reuse ... is it more proper to (map function data) or have the map inside the function where the output is just the "transformed" data (function data)? And does this apply to filters too?
@eric799 see https://stuartsierra.com/2015/08/10/clojure-donts-redundant-map for advice (that whole series is good)
Thanks, thats a very good series ... unfortunately I only understood 50% of it .. I'm going to have to rethink what I'm doing. I'm going with the theory that if it looks messy. I'm doing it wrong.
Hello everyone ¿Do you know where are in-memory ring sessions stored? ¿Where is the atom that holds all sessions information?
The default store is ring.middleware.session.memory/memory-store
. Are you looking for a way to inspect it?
You are correct. But that instance has the method session-atom
, which returns the atom for you
My suggestion is that you explicitly create a MemoryStore
, then pass it in the options map to wrap-session
.
(def session-store (mem/memory-store))
(def app
(wrap-session handler {:store session-store})
Ok, I thought the same idea, but I wanted Ring to continue to be in control of everything. And then I wonder how does ring use the same atom in subsequent requests?
No. The middleware wrap-session
will use the same session store for each request it looks at
You're welcome! I couldn't answer without looking at the source, specifically https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/middleware/session.clj and https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/middleware/session/memory.clj. It might be worth to check out.
I think I got it. In this HTTP server declaration:
(mount/defstate http-server
:start (http/start
{:handler (wrap-session handler/app {:cookie-attrs {:http-only true}})
:port 3000})
:stop (http/stop http-server))
The atom is (indirectly) created when wrap-session
is evaluated (via mem/memory-store
) and is bound to the anonymous function (the middleware), so there is no way to access it.