beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
st3fan 2020-11-30T00:11:06.039400Z

Sorry - what I mean is that I wish I could just Clojure data structures and not bother with SQL at all

st3fan 2020-11-30T00:11:37.039600Z

If they would somehow magically persist to disk

Ben Sless 2020-11-30T04:11:30.040Z

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

william 2020-11-30T11:40:06.042Z

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

octahedrion 2020-11-30T13:09:50.042600Z

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

👍 1
1
2020-11-30T13:41:40.044200Z

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]

dgb23 2020-11-30T14:12:56.044800Z

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

dgb23 2020-11-30T14:13:27.045Z

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

2020-11-30T14:15:29.045200Z

Perfect, thanks for these solutions!@denis.baudinot

2020-11-30T14:17:01.045400Z

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

scythx 2020-11-30T14:19:34.045700Z

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?

dgb23 2020-11-30T14:28:26.046Z

The comp version produces a transducer, which evaluates eagerly. See: https://clojure.org/reference/transducers

2020-11-30T14:37:06.048500Z

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/

scythx 2020-11-30T14:41:07.048900Z

thank you! this is what i need exactly!

👍 1
william 2020-11-30T14:43:45.049300Z

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

william 2020-11-30T14:44:05.049500Z

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

scythx 2020-11-30T14:44:54.050200Z

okay, i'll take a look at that

rmxm 2020-11-30T15:31:34.052300Z

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

dpsutton 2020-11-30T15:38:46.052900Z

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

rmxm 2020-11-30T15:41:32.054Z

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

dpsutton 2020-11-30T15:49:54.055100Z

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

rmxm 2020-11-30T15:59:04.055300Z

fair enough, thanks 🙂

2020-11-30T17:30:21.055600Z

@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

❤️ 2
Schmoho 2020-11-30T19:06:45.055800Z

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

Schmoho 2020-11-30T19:09:32.056100Z

(->> [#{{: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