Fork me on GitHub
#beginners
<
2022-11-24
>
dharrigan14:11:07

Say you have a map like this {:a/x 1 :a/y 2 :b/x 1 :b/y 2} is there a way I can pull out all the namespaced as and namespaced bs and put them into a new map like this {:a {:a/x 1 :a/y 2} :b {:b/x 1 :b/y 2}}?

Bob B14:11:39

the first thing that comes to mind is group-by to get the grouping and then update-vals with into {} to put the entries back into a map; it could be done with a reduce as well

Martin Půda15:11:28

(-> (group-by (fn [[k v]] (namespace k)) {:a/x 1 :a/y 2 :b/x 1 :b/y 2})
    (update-keys keyword)
    (update-vals #(into {} %)))
=> {:a #:a{:x 1, :y 2}, :b #:b{:x 1, :y 2}}

Martin Půda15:11:16

Or (group-by (comp namespace key) {:a/x 1 :a/y 2 :b/x 1 :b/y 2})

gratitude 1
clojure-spin 1
dharrigan15:11:47

thank you 🙂

stopa16:11:31

Hey team, I want to run a clojure server with aurora, on aws (one caveat: server will need to support websockets). I am assuming I would use elastic beanstalk, uberjar and boom. I’m about to start doing this, but if ya’ll know of a tutorial that takes a basic clojure project and hosts it on aws, I would love to read it!

jumar18:11:42

When it comes to deployment then Clojure uberjar isn’t really different from Java so you might search for info about java deployment too

practicalli-johnny06:11:41

AWS Beanstalk for Java has a tomcat platform (Java WAR file) and Java SE platform (Java jar file - e.g a Clojure Uberjar), so Java SE platform seem the appropriate choice There is a general Java overview of what's required https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-platform.html It recommends a Procfile which I assume would be

web: Java -jar application.jar $PORT
The Clojure app should include a -main function in the main namespace that takes the port environment variable as an argument. Or skip the argument and use System/getenv to read the port value assigned by beanstalk The Clojure main namespace will also need a genclass directive in the ns definition

practicalli-johnny06:11:53

For setting up websockets, you may need some reverse proxy (e.g nginx). If so then there are probably examples on Stack Exchange/Overflow

stopa16:11:14

Thank you John! Makes a lot of sense