Sorry - what I mean is that I wish I could just Clojure data structures and not bother with SQL at all
If they would somehow magically persist to disk
Beware that for is lazy. Laziness and side effects don't mix well together. I recommend either coercing it via doall or using mapv. Also take a look at https://github.com/TheClimateCorporation/claypoole
how could I find all the keywords in an arbitrarily nested data structure (which has sets, arrays, etc inside)?
(filter keyword? (tree-seq seqable? seq my-map))
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)))
Perfect, thanks for these solutions!@denis.baudinot
I was just thinking of a version with comp, I like it.
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?
The comp version produces a transducer, which evaluates eagerly. See: https://clojure.org/reference/transducers
Hi @raefaldhiamartya First of all, you can watch this video https://www.youtube.com/watch?v=CBL59w7fXw4 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 https://purelyfunctional.tv/article/clojure-web-security/
thank you! this is what i need exactly!
I have problems with this in clojurescript when the map contains strings, because:
(seq "a")
evaluates to ("a")
I have problems with this in clojurescript when the map contains strings, because:
(seq "a")
evaluates to ("a")
okay, i'll take a look at that
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 🙂
@raefaldhiamartya Last but no least, @kelvin.mai002 just post the third part of video tutorials series about how to using Buddy auth library. https://youtu.be/FcxO5VCPLi4
something like this
(let [a (atom [])]
(clojure.walk/prewalk #(if (keyword? %) (do (swap! a conj %) %) %) [#{{:a '(1 :b)}}])
@a)
;; => [: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