This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-30
Channels
- # babashka (7)
- # beginners (25)
- # calva (22)
- # cljs-dev (1)
- # clojure (62)
- # clojure-europe (118)
- # clojure-hamburg (4)
- # clojure-israel (2)
- # clojure-nl (2)
- # clojure-uk (6)
- # clojured (1)
- # clojurescript (23)
- # conjure (11)
- # cursive (3)
- # datomic (14)
- # duct (2)
- # emacs (12)
- # figwheel-main (1)
- # gratitude (1)
- # hyperfiddle (4)
- # joyride (72)
- # lsp (46)
- # luminus (1)
- # malli (1)
- # off-topic (54)
- # pathom (19)
- # polylith (11)
- # releases (2)
- # sci (22)
- # shadow-cljs (4)
- # vim (11)
- # xtdb (52)
I have a map
(def data {:a "A" {:b "B" :c "C" :d "D"}})
how can I use update-in to update both keys :c and :d so that the resulting map is `
{:a "A" {:b "B" :c "R" :d "T"}}
`Hi. Whatβs your favorite book or course you took to learn Data Structure and Algorithm? Is there a good one done in Clojure?
Better look for books in Java, python. No algorithm books in clojure. You can try SICP, how to design programs written using lisp/racket lang
Not necessarily looking for one written in clojure (i thought there might be). Was more interested in your favorite one:the one that taught you well.
My favorite https://algs4.cs.princeton.edu/home/
The "classic" books on Algorithms are usually big and and require a lot of work. For a less formal and lightweight intro, I think, Grokking algorithms is nice.
(filter #{"foo"} ["foo" "bar"])
(filter #(= "foo" %) ["foo" "bar"])
which of these is better and is there a blog post about it?If you were filtering for more than one value itβs also trivial to do it with sets, not so much with the 2nd method
Right, rarely would you want to filter on the identity of a whole thing in some collection. More often on some characteristic of it. Makes sense though if you want to count how many of a thing exists in a collection, for instance.
Good day,
Does Clojure have anything similar to Elixir's IO.inspect
? Which allows you to output the value at any point in a pipline without interrupting its execution.
Example:
(-> args
(fun1)
(fun2)
(IO.inspect)
(fun3))
A simpler solution is to use doto
:
(-> args
(fun1)
(fun2)
(doto pp/pprint)
(fun3))
(doto x f)
calls (f x)
and then returns x
I use it with tap>
all the time to send values to Portal (or Reveal or REBL or any other tap>
-listener you have registered), since tap>
rather annoyingly returns true
or false
rather than the value you tap!
I'm running into this error when I try these:
Execution error (ArityException) at user/count-nums (REPL:13).
Wrong number of args (3) passed to: clojure.core/remove
Here's my code:
(defn count-nums [nums]
(->> nums
(remove #(< % 5))
(doto pprint))
count)
You can't use doto
with ->>
because the argument will be in the wrong place.
You could do this:
(defn count-nums [nums]
(->> nums
(remove #(< % 5))
(#(do (pprint %) %))
count))
Ugly, but it will work.Sometimes it's just easier to define a debug
function for stuff like this:
(defn debug [x] (pprint x) x)
(-> args
(fun1)
(fun2)
(debug)
(func3))
(defn count-nums [nums]
(->> nums
(remove #(< % 5))
(debug)
count))
Since debug
takes only one argument and returns it (after printing it) you can use it with both ->
and ->>
Many people have their own little spy
function like that. You can also get it from libraries like https://github.com/cloojure/tupelo and some offer more advanced forms of spying like https://github.com/philoskim/debux