This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-11
Channels
- # beginners (18)
- # boot (1)
- # cider (48)
- # cljs-dev (5)
- # cljsrn (2)
- # clojure (34)
- # clojure-greece (1)
- # clojure-mexico (3)
- # clojure-spec (6)
- # clojure-uk (3)
- # clojurescript (67)
- # cursive (1)
- # data-science (2)
- # defnpodcast (2)
- # fulcro (10)
- # jobs (3)
- # klipse (14)
- # off-topic (9)
- # pedestal (2)
- # re-frame (8)
- # spacemacs (2)
- # specter (2)
- # vim (2)
- # yada (1)
Guys, I am playing with some Java NIO in Clojure. I want to create a function that receives a multiplexor (`java.nio.channels.Selector`), performs a select, collects all the selected keys and clear the selector (for the next selections). I have a prototype, but it is looking procedural. Is there a more idiomatic way of doing this?
(defn select-now!
[multiplexor]
(.selectNow multiplexor)
(let [selected-keys (.selectedKeys multiplexor)
it (.iterator selected-keys)]
(loop [result nil]
(if-not (.hasNext it)
result
(let [nxt (.next it)]
(.remove it)
(recur (conj result nxt)))))))
I also tried using the selected-keys
set as a seq
, since it is Iterable
, and doing a .clear
on the whole set afterwards, but the same channels kept being selected, even though their data was already read
Looks like you really have to use the it.remove()
call
Well yeah, according to the documentation, the only way to remove a SelectionKey from the selected keys set is using the .remove
method, either from the set or from the iterator
Did anyone here ever had this experience where they try to run test-project on cider (emacs) and no test is run?
“No assertions (or no tests) were run. Did you forget to use ‘is’ in your tests?"
My project is called “papo”. The test file is “test/papo/messaging_test.clj”. I have tried reloading/refreshing the repl, but the test-project
command does not work. The test-namespace
command works, tho.
I haven't had that experience, but I wonder whether you need to add test
as a src dir in project.clj
.
I see. I am going to try that when I have a chance! I thought that following Leiningen’s conventions was good enough 🧐
Thanks @U077BEWNQ!
Didn’t work 😞
I added :source-paths ["src" "test"]
to my project.clj
file explicitly
lein test works normally, cider-test-run-project-tests
doesn't
I've just read about transducer and couldn't quite understand it
Until I read this: https://stackoverflow.com/questions/26317325/can-someone-explain-clojure-transducers-to-me-in-simple-terms
So from what I understand, it is a better way to apply function on a collection in terms of perfomance and modularity
Shouldn't we just use always use transducer whenever we can? Am I missing something?
@boldaslove156 One benefit of transducers comes when you have a series of operations to do on a collection. If you thread a collection through a series of map/filter/etc, each operation creates a new intermediate sequence result. If you compose the transducer versions of those operations, then no intermediate sequences are created.