This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-29
Channels
- # announcements (5)
- # beginners (25)
- # calva (53)
- # clj-kondo (9)
- # clojure (25)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-uk (1)
- # conjure (2)
- # data-science (1)
- # datalevin (4)
- # datascript (6)
- # deps-new (5)
- # emacs (5)
- # etaoin (6)
- # figwheel-main (1)
- # fulcro (46)
- # gratitude (3)
- # hyperfiddle (8)
- # introduce-yourself (13)
- # lsp (13)
- # nextjournal (5)
- # off-topic (2)
- # pathom (4)
- # polylith (11)
- # re-frame (16)
- # releases (4)
- # scittle (67)
- # shadow-cljs (38)
- # slack-help (4)
- # specter (13)
- # sql (29)
- # squint (21)
- # test-check (3)
- # vim (13)
- # xtdb (15)
Good day,
I've noticed a bunch of dep's files in .m2/repository
, the vast majority aren't related to any project in use, just the result of toying with different libs. What's the best practice to remove them?
I executed below code in repl it returning nil
, how can I avoid returning nil if condition fail
(def a "B")
(when (= a "A")
"testing")
What do you want to return? (You can use 'if' rather than 'when' to allow for a specific failure case)
basically I am updating a variable using assoc statement, but I wanted to check few condition before that, which I have put in the when logic, when condition is false, it returning nil
and acting as
(-> a
nil)
But what do you want it to return? Expressions return something (even if it's nil). If you want to return something changed or something unchanged based on some condition, that's a case for if
, or if you have a bunch of different conditions that can lead to different changes, maybe cond->(>)
@U013JFLRFS8, cond->
worked for me, thank you for your suggestion 🙂
I'm gathering resources for learning Clojure here - https://www.are.na/itay-dreyfus/clojure-0rhdjyippgc Happy to add anything related 🙂
Ok gradually getting the hang of Clojure trying PEZ/rich4clojure problems on github
(defn power
"derive power set of in-set"
([in-set] (power in-set '(#{})))
([[this-in-set & rest-in-set] power-res]
(if this-in-set
(recur rest-in-set
(concat power-res
(map #(conj % this-in-set) power-res)))
(set power-res))))
In this power set generator I wondered if I could replace the concat ..map with mapcat but couldn't find it. Is there a template which shows before code where mapcat applies?
(mapcat f coll)
is equivalent to (apply concat (map f coll))
. So it doesn’t apply here.
Unless...
... unless you consider that for each item of power-res you do two things and that instead of doing these two thing separategly in two passes over power-res, you do them at once
(defn power
"derive power set of in-set"
([in-set] (power in-set '(#{})))
([[this-in-set & rest-in-set] power-res]
(if this-in-set
(recur rest-in-set
(mapcat (fn [sets] [sets (conj sets this-in-set)]) power-res))
(set power-res))))
Grand thanks the apply bit was missing in my understanding when I read the 'doc'. I'll have to digest the mapcat fn conj re-write when Im less tired but it looks good.
(defn power [items]
(reduce (fn [sets x] (into sets (map #(conj % x)) sets)) #{#{}} items))
How do I get the value of a key which is a character? The following returns nil
(get \a {\a 1 \b 1 \2)
if the map is nil, then (nil \a)
will throw a Null Pointer Exception, so usually people would do (get map \a)
I find (get m k)
easier to scan visually. I prefer:
• (:key m)
when I know the key (as a symbol) statically,
• (get m k)
otherwise.
I have a vector thats like [#uuid "00000000-0000-0000-0000-000000000000" :book "The Book Title" [:mystery :science-fiction]] .. is there a way to map the positions to field names in a let other than like like (let [:id (first book-vector) :type (nth 2 book-vector) :title (nth 3 book-vector) etc. etc.
if you want to put it into a map there's also zipmap