Fork me on GitHub

how could I find all the keywords in an arbitrarily nested data structure (which has sets, arrays, etc inside)?


I have problems with this in clojurescript when the map contains strings, because: (seq "a") evaluates to ("a")


something like this

(let [a (atom [])]  
  (clojure.walk/prewalk #(if (keyword? %) (do (swap! a conj %) %) %) [#{{:a '(1 :b)}}])
;; => [:a :b] 
seems like a straightforward way to what I understand your first question to be, however I don't understand your addition to it. there is probably some nicer way to do it though


(->> [#{{:a '(1 :b)} :c} :d]
     (tree-seq seqable? identity)
     (filter keyword?))
;; => (:a :b :c :d)
is another basically you'll want something like walk or tree-seq


(filter keyword? (tree-seq seqable? seq my-map))

šŸ‘ 1

I have problems with this in clojurescript when the map contains strings, because: (seq "a") evaluates to ("a")

Michaƫl Salihi13:11:40

Hi, is there a good one-liner to get this result? Someone see another better solution? More idiomatic and/or concise?

(->> [1 2 3 4 5] (filter even?) (mapv #(* % 10)))
;; => [20 40]


your code is fine! transducer version: (into [] (comp (filter even?) (map #(* 10 %))) [1 2 3 4 5])


list comprehension version: (into [] (for [n [1 2 3 4 5] :when (even? n)] (* 10 n)))

Michaƫl Salihi14:11:29

Perfect, thanks for these solutions!@U01EFUL1A8M

Michaƫl Salihi14:11:01

I was just thinking of a version with comp, I like it.


The comp version produces a transducer, which evaluates eagerly. See:


Hello, i need to create simple API web server for my vue.js App. The server only need auth & crud stuff. I don't really understand about web security. So is it recommended to use only reitit and add some security stuff (via library if there is any, or implement myself (hopefully there's some resources i could read)) or use a framework such as luminus/pedestal?

Michaƫl Salihi14:11:06

Hi @raefaldhiamartya First of all, you can watch this video It's not recent so the libraries (friend, buddy, etc) have evolued but the main security concerns are still relevant. I recommend reading also this posts


thank you! this is what i need exactly!

šŸ‘ 1
Michaƫl Salihi14:11:08

You"re welcome! If you using Reitit Ring so I recommanded to adding this Ring middleware: > This library attempts to automate the process, by providing sensible and secure default configurations of Ring middleware for both websites and HTTP APIs.


okay, i'll take a look at that

Michaƫl Salihi17:11:21

@raefaldhiamartya Last but no least, @UGJ8075QQ just post the third part of video tutorials series about how to using Buddy auth library.

ā¤ļø 2

hey when you are reducing something with update-in conj. like (reduce #(update-in %1 [:a] conj %2) {} ["a", "b", "c"]) how can I have control over final output type, conj by default doesnt put into vector


common to see (fnil conj []) as the updating function. you could also use {:a []} as your initial value


thanks for fnil, seems bit awkward, i provided static key, but its actually dynamically mapped based on initial-acc


i'm not sure what seems awkward. its quite common from my experience. and its purpose is what value to provide in the event of a nil argument, which is pretty much exactly your situation. it seems quite tailored to your current requirement


fair enough, thanks šŸ™‚