Fork me on GitHub
Alexey Baryshnikov09:10:59

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 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 type


So ultimately the question seems to just be about "how do I add items to a list"?


Many possibilities there: conj, into, concat, ...


The 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,...


Can you provide an example of what you want to achieve?


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.

Dmitrii Sherstobitov11:10:42

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?


can you write what you try to achieve in another language? (js etc)

Dmitrii Sherstobitov11:10:24

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[]
   # do somthing and
   return map[]


you can use a cond for that, just a sec

  (and (not a) (not b))
    ;; some processing
  (and a (not b))
    ;; some processing
  (and (not a) b)
    ;; some processing
    ;; some processing

Dmitrii Sherstobitov11:10:28

got it, thanks a lot!

✌️ 1
🙂 1
Eric Boatman18:10:55

When 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?

Eric Boatman19:10:08

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?


Yes, I want to write-session to specific ring session.


Then you can pass it in the options map to the session middleware


But isn’t it a default instance of MemoryStore class?


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})


Now you can play with the atom through (mem/session-atom 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?


Ring uses whatever session store you give to wrap-session


And you don't give it anything, it reverts to mem/memory-store as a default


Does it creates a new atom on each request?


No. The middleware wrap-session will use the same session store for each request it looks at


Okok. Thanks a lot 🙌


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.


Yes, you are bang on. Very hard to access it without creating it first yourself and passing it in!

👍 1