This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-15
Channels
- # announcements (2)
- # babashka (27)
- # beginners (53)
- # boot (3)
- # calva (5)
- # cider (1)
- # clj-kondo (46)
- # cljdoc (38)
- # cljs-dev (40)
- # cljsrn (1)
- # clojars (5)
- # clojure (61)
- # clojure-europe (124)
- # clojure-germany (3)
- # clojure-losangeles (6)
- # clojure-nl (12)
- # clojure-uk (11)
- # clojurescript (44)
- # clojureverse-ops (7)
- # datomic (13)
- # events (3)
- # introduce-yourself (1)
- # jackdaw (5)
- # lsp (115)
- # malli (1)
- # off-topic (16)
- # polylith (2)
- # releases (1)
- # remote-jobs (6)
- # shadow-cljs (10)
- # sql (2)
- # timbre (1)
- # tools-deps (30)
- # vim (34)
- # xtdb (20)
@josh604 could you explain the (juxt key f)
part?
It basically applies (key) and (f) to each Val because “mapping over a map” actually goes KV pair-by-pair?
oh Okay… melding into brain … 😄
(juxt key (comp f val))
will return segments like :a 48 :n 96
so we add (into {} …)
to make it a map ?
Juxt looks super useful I wish I worked it into my flow more
@hiredman’s snippet is the actually correct expression and yes, juxt returns a function which will return a vector of the application of each function, so in this case it returns a map entry as a [k v] pair
The “will return a vector of…” is not in the docstring
that cleared up a lot
Maybe you are looking at some other docstring, but is says on https://clojuredocs.org/clojure.core/juxt that juxt returns a function that "returns a vector containing the result of applying each fn to the args"
Which one do you prefer to read? Or is there a better third option? (1️⃣ / 2️⃣ / comment)
;; 1
(->> @eventlog
(filter (fn [e]
(contains? #{:create :modify}
(-> e :e :kind))))
count)
;; 2
(->> @eventlog
(filter #(#{:create :modify} (-> % :e :kind)) )
count)
I like using the set as a function instead of contains of the second version. But i dont like the function shorthand there, it’s slightly confusing.
Like this?
;; 3
(->> @eventlog
(filter (fn [e]
(#{:create :modify} (-> e :e :kind))))
count)
(count (filter #(-> % :e :kind (#{:create :modify})) @eventlog))
another onemaybe even?
(->> @eventlog
(map #(-> % :e :kind))
(filter #{:create :modify})
count)
Does this result in one more intermediate collections being created ? COmpared to the original ?
yeah the map will produce a lazy seq, theres an extra seq but numbers of things processed should be same
yes, it will create intermediate collection. To avoid it - replace ->>
with transducer equivalent
(count (sequence (comp (map ...) (filter ...)) @eventlog)
is it possible to conj
two maps making sure the first map will always be first in order in the final map?
Example:
(conj {:uuid 123} {:a 234 :b 35 :z 345})
;=> {:uuid 123 :a 234 :b 35 :z 345}
This small example actually works, but some larger maps conjoin with strange orderingmaps are unordered
@slack.jcpsantiago there is something by amalloy you might find interesting … https://github.com/clj-commons/ordered
I am using figwheel for developing frontend. I've got a few nested reagent components. How do you access the states of the components at runtime using repl...? I tried add-watch function... it breaks my component!!
You want to see component state in the REPL ? I am pretty sure you can see it in the browser with the extra dev tools … REPL I’m not sure about
extra dev tools?
Hi, Sorry to bother you. Is there an example of using devtools for debugging active run... ?
No problem 🙂
cljs-devtools
just pretty prints cljs data structures to the javascript console.
Without cljs-devtools
:
(js/console.log {:a 1}) ;; => prints gibberish
With cljs-devtools
(js/console.log {:a 1}) ;; => nice explorable object you can interact with from your console
To inspect your component state at runtime, just js/console.log
it and cljs-devtools will present it well.With ruby I had to make a tic tac toe game which works at a prompt. Is there a tutorial how to make it work in clojure ?
I’m trying to use clojure.xml/parse
but I keep getting a file not found as I’m passing a string through an InputStream.
it points at a path that is in the doctype of the xml like so:
It seems likely that the underlying xml reader is pulling in the dtd automatically, perhaps so it can resolve entity references or something.
This can probably be turned off using one of the options listed in https://clojure.github.io/data.xml/#clojure.data.xml/parse
The entity-related ones and :support-dtd
are the first ones I'd try.
np, xml is a beast. good luck!
(and just to be clear, you mean clojure.data.xml/parse
, not clojure.xml/parse
?)
initially i tried clojure.xml/parse
but based on @U7ZL911B3 and @U050ECB92’s advice I switched to clojure.data.xml/parse
and turning off dtd support immediatly fixed my problem
I guess was more of a java and xml question but I’m very happy I got help here and got pointed to the other lib!
clojure.xml is deprecated, FYI - will be more officially marked in next release AFAIK use clojure.data.xml instead
@dpsutton thanks, it is another game then I have in mind but I could use some ideas I think