This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-05
Channels
- # announcements (14)
- # babashka (51)
- # beginners (154)
- # calva (24)
- # cider (4)
- # clj-kondo (24)
- # cljfx (11)
- # cljs-dev (3)
- # clojure (259)
- # clojure-europe (14)
- # clojure-nl (2)
- # clojure-seattle (8)
- # clojure-spec (6)
- # clojure-taiwan (1)
- # clojure-uk (52)
- # clojurescript (123)
- # conjure (43)
- # core-async (15)
- # datomic (14)
- # events (1)
- # fulcro (90)
- # helix (7)
- # jobs (6)
- # meander (10)
- # nrepl (1)
- # off-topic (13)
- # pathom (1)
- # portal (8)
- # re-frame (7)
- # reveal (11)
- # shadow-cljs (99)
- # spacemacs (11)
- # testing (11)
- # vim (63)
Version 2.0.146 is out with the following fixes 🎉: • Fix: https://github.com/BetterThanTomorrow/calva/issues/883 • Fix: https://github.com/BetterThanTomorrow/calva/issues/906 • Fix: https://github.com/BetterThanTomorrow/calva/issues/884 • Fix: https://github.com/BetterThanTomorrow/calva/issues/888
(defn validate2
[validators suspect] #break
(reduce-kv (fn[acc k v]
(and acc ;; The previous keys were validated
(contains? suspect k) ;; the suspect contains the key in question
(v (suspect k)))) ;; the value of that key in the suspect validates according to the validator function
true validators))
What I do in cases like that (nice small functions) is that I instrument the whole defn. So instead of that #break
, I evaluate the code using the debug instrument command instead of the regular one.
I have noticed that JS objects in the cljs REPL (or rather in the source code, when evaluating an expression there) are printed in an unhelpful way, such as (`|` is the cursor position when I press Alt-Enter):
js/firebase | => :shadow.cljs/print-error!
(.app js/firebase) | => #object[K [object Object]]
(Wrapping the result with js->clj
does not help either.) Is that a known limitation? Thank you!I certainly recognize it. Happens in typescirpt and javascript as well often. Not sure it is the same case, but what I do in TS is that I call JSON.stringify() on the object.
Another thing I often do is that i def
things in the functions. Doesn’t really help all that much in a reduce, but as a general tool it can be useful.
That should instrument the function. So that when you run it, it should break. Doesn’t happen?
About that def
technique: https://clojureverse.org/t/exploring-using-def-x-x/3946
Now I understand a lilte how this one is working
(defn maps->csv [coll-of-maps]
(let [header (-> coll-of-maps first keys) ;; we take the keys to use as a csv header
to-vals (apply juxt header) ;; a function that will extract the map values in the same order as header
lines (map (fn[m] (->> m ;; we take m
to-vals ;; extract the values
(clojure.string/join ", "))) coll-of-maps) ;; and join them as strings
header-string (->> header (map name) (clojure.string/join ", "))] ;; header string
(str header-string "\n" (clojure.string/join "\n" lines))))
Hi @andyfry01, @yadolghintev388, and @zeiglerr, welcome to the channel 👋