This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-04
Channels
- # announcements (2)
- # beginners (30)
- # calva (30)
- # cider (10)
- # cljs-dev (4)
- # clojure (59)
- # clojure-nl (2)
- # clojurescript (21)
- # cursive (22)
- # datascript (3)
- # datomic (5)
- # duct (5)
- # figwheel-main (1)
- # flambo (2)
- # fulcro (8)
- # jackdaw (1)
- # joker (9)
- # off-topic (24)
- # pathom (1)
- # re-frame (2)
- # rewrite-clj (4)
- # shadow-cljs (163)
- # sql (14)
- # tools-deps (6)
- # vim (24)
- # yada (3)
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 :k1
s 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/m
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
vals
(map :k1)
(reduce str))
"v1v3"
Cool, thanks. I ended up using something like the 1st/3rd snippets you posted:
(->> (select-keys big-map relevant-keys)
vals
(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.
@here I just wanted to start with just creating CRUD operation,which is the best framework pls let me know
Don't know the best framework (I honestly think it is no framework) but the Luminous creator wrote a book https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition
Thank you
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
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.
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.
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.
I see now.
^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.