Fork me on GitHub

If I have a map like {1 {:k1 v1 :k2 v2}, 2 {:k1 v3 :k2 v4}} is there a better way to map or reduce over all :k1s than

(reduce-kv (fn [res _ {sub-key :k1}] (do-stuff res sub-key)) init the-map)
` ?


I’m not sure if I get what you’re after but maybe something like this?

user> (def m {1 {:k1 "v1" :k2 "v2"}, 2 {:k1 "v3" :k2 "v4"}})
user> (map :k1 (vals m))
("v1" "v3")


Or this perhaps?

user> (map #(select-keys % [:k1]) (vals m))
({:k1 "v1"} {:k1 "v3"})


And you can also combine map and reduce like this for example:

user> (->> m
           (map :k1)
           (reduce str))


Cool, thanks. I ended up using something like the 1st/3rd snippets you posted:

(->> (select-keys big-map relevant-keys)
     (mapv :the-subkey-i-want)
     (reduce *'))


Admittedly what I am doing is already quite messy, but I’m trying to untangle some spaghetti Python into Clojure so I just want to get it working first, and then clean it up


Yeah that’s what I also often do. First get it to work and then make it properly. If something feels or looks ugly or too complex there’s a usually simpler way of thinking it.

Jeevaraj MV14:05:10

@here I just wanted to start with just creating CRUD operation,which is the best framework pls let me know

Eric Ervin21:05:04

Don't know the best framework (I honestly think it is no framework) but the Luminous creator wrote a book


Not a question, just a thought: it's easier for my brain to read/write #(...) functions if I think of them as a partial function rather than an anonymous function

Kari Marttila17:05:43

All Ring examples seem to use Leiningen or Boot. Is there some documentation or blog which gives short instructions how to configure and use Ring with deps.edn for development use etc?


Something like this might suit:

{:paths ["resources" "src"]
 :deps {hiccup {:mvn/version "1.0.5"}
        ring {:mvn/version "1.7.1"}}}


@kari.marttila Not sure what you're looking for. We use Ring etc with deps.edn all the time and I don't know what instructions or configuration you think you need? It's just dependencies.


We used to use Boot and before that we used to use Leiningen and it's all the same.


We didn't use any plugins.


Here's an example repo using deps.edn with Ring, Selmer, Compojure.

Luiz Sol22:05:04

Hi everyone. I'm just starting to learn clojure and to do so I'm trying to port an application I've build in the past to the clojure ecosystem (clj, cljs and datomic). I was able to find lots of materials on the first two topics but I'm not being able to find a beginners guide to building and configuring datomic. Most guides either assume that I'll use only the in-memory version of datomic or that someone else already took care of deploying a datomic envinronment. *TL;DR*: Is there any place in which I can learn how to set up and configure datomic pro starter with a postgresql (preferably using docker)?


Better skip the Datomic part if you're just starting with Clojure - at least, that would be my recommendation. Start with something you're already familiar with - that is use the same DB technology if possible. You can later rewrite that part and compare to the first version.

Luiz Sol17:05:15

Maybe you're right. Thanks a lot.


I was looking through some code. I saw a map like {^:height height} is it similar to using ^Observable for a java type.


@sotrhraven That's adding metadata to a Clojure object. Any map of data can be added to (most) Clojure objects.


^Observable is a type hint, which is slightly different.


ok I will look into metadata on the clojure website.


^Observable x will add the metadata {:tag Observable} to x so it is a type of metadata, but it's specifically for the compiler (to avoid reflection etc).


But metadata can be arbitrary data. In Clojure 1.10, you can add metadata to objects to satisfy extensible protocols which is really powerful.