This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-31
Channels
- # architecture (5)
- # beginners (35)
- # boot (150)
- # cider (1)
- # clara (7)
- # cljs-dev (131)
- # cljsrn (10)
- # clojure (76)
- # clojure-austin (3)
- # clojure-berlin (1)
- # clojure-brasil (1)
- # clojure-chicago (2)
- # clojure-dusseldorf (1)
- # clojure-italy (30)
- # clojure-nl (2)
- # clojure-russia (40)
- # clojure-serbia (2)
- # clojure-spec (25)
- # clojure-uk (13)
- # clojured (2)
- # clojurescript (106)
- # core-async (29)
- # datascript (65)
- # datomic (38)
- # emacs (8)
- # funcool (8)
- # hoplon (6)
- # jobs (3)
- # klipse (93)
- # luminus (16)
- # lumo (4)
- # off-topic (2)
- # om (11)
- # onyx (13)
- # pedestal (4)
- # protorepl (3)
- # re-frame (40)
- # reagent (31)
- # ring (6)
- # ring-swagger (4)
- # slack-help (5)
- # spacemacs (13)
- # untangled (17)
- # vim (2)
It seems simple enough, but my google-fu was not strong enough to find a reasoable solution
or if you prefer reduce
: (reduce (fn [m val] (assoc m (compute-index val))) {} my-original-seq)
(if your original seq is actually a Java array, not a Clojure list/vector, then you'll need to do array-seq
like jr mentioned)
That looks more reasonable, thanks
Though a question, map doesn’t seem to pass in the original index
is there a way to get that index in the function?
That was a dumb question
thank you
@spacepluk using boot, there is https://github.com/alandipert/e2j/blob/master/build.boot#L42
Anyone using nippy to serialize custom types to string storage? I'm having trouble getting freeze/thaw to work and I think it's related to string encodings. Working example would be really helpful.
hi, I have an idiomatic clojure question: What's the best way to add options to a multimethod, where very few of the defmethods need the options?
For more context, I'm trying to make a more performant clojure.java.data
https://github.com/clojure/java.data/blob/master/src/main/clojure/clojure/java/data.clj#L41
I'd like to support multiple key conversion functions, not just keyword
add an options map as the last arg?
then perhaps add a wrapper fn with two arities, to pass {} for the default case
(defmethod to-clj :default [instance & {:keys [keep-coll keep-nil? key-fn] :or {keep-coll nil keep-nil? false key-fn identity}}]
@alexbaranosky I did something like that, but the arguments quickly got out of hand
that's not an options map, that's keyword args
let me draw up an example
(defmulti to-date (fn [x options]
(type x)))
(defmethod to-date Calendar
([cal options]
(.getTime cal)))
(defmethod to-date Date
([date options]
date))
(defn convert-to-date
([x]
(to-date x {}))
([x options]
(to-date x options)))
not sure if that's "idiomatic", but it works
Yeah that makes sense
so if you have a ton of methods, the convert-to-date saves a lot of typing up arities, basically
Is there a standard way to merge the provided options with the defaults, or just (merge default-opts opts)?
>> "where very few of the defmethods need the options?" Maybe I misunderstood ... I was under the impression most methods wont care about the options?
for the ones that care, you can just use clojure.core/merge
Yeah, okay
And I will use (update :key ...) if I need to change one option as I call recursively
update sounds like the wrong fn
update is for changing values with a function
assoc is for setting a value
I need to set a value based off its previous value
Hi all, I’m trying to import a Clojure record into a java class but I keep getting error: cannot find symbol
I’ve compiled a jar with the record in question and AOT compile the namespace with the record. I am now trying to create an instance of record in another project, but keep running into the above error. Can records be imported this way? And is there anything I have to do to make them accessible in Java? Thanks!
Has anyone ever toyed with making the clojure test runner asynchronous with core.async? Our company does integration testing only, but we could see some decent speed if only we didn't have to wait for one test to finish executing before beginning the next one.
@tjtolton why not just use an alternative test runner like https://github.com/weavejester/eftest that executes tests in parallel?
the tests themselves are identically created as used by core.test
hmm.. one difference is that eftest seems to do parallelism, but not async, so each test will block a thread.
this is true; but honestly? Unless you're running hundreds of tests simultaneously and you know that all of your code is i/o bound, you're not overly likely to see any difference (and this is simpler)
well, i/o bound and written in a non blocking way with core.async
thanks, @U236LQYB0 this looks like a great option! its much better than what I was asking for.
I don't. Since eftest allows you to specify a directory to search for tests in, you could probably make a namespace in your test directory that has the code to require eftest.runner and a main function that runs the tests, which you can then set up an alias in lein to run instead of lein test
but that may not be the best way to do it. You should ask directly on the clojure channel instead of this thread to see if anyone else has a better suggestion
Hi. I am not sure if this is the right type of question for this channel, but has anyone done Clojure project where clojure server has live streamed audio to website? I would like to do this in my project and I would love to know what kind of techniques people have used to solve this problem.
Just from googling the source from https://github.com/jblomo/iceclient might be helpful.
Depends on what you’re trying to do. The JVM is not ideally suited for real-time(ish) applications but you might well be able to get away with it depending on your constraints.
I do know the SoundCloud folks use Clojure, although I’m not sure exactly for what. If any of them are hanging out here they’re going to be able to give more intelligent answers than me.
This is mostly for my own media server project so performance is not that a big problem at least for now. The end game for me would be on-the-fly transcoding and streaming audio
Might make sense to use external streaming software and just configure it through clojure.
@neurogoo I was able to do better-than-real-time for the stuff I was doing, so for a hobby project I would think it would be reasonable. But I haven’t surveyed the options - the Java stuff in the project I referenced worked for me. You may find it challenging to work with MP3, however, since it is (or at least was a few years ago) still under IP.
I guess I could trancode to something easier-to-modify format with ffmpeg and then stream that. Another option would to use ffserver, but I have no idea yet how easy that would be to integrate to my applications workflow. I have to do some experiments and try things out. Thank for all your help
I’m using clojure.data.xml/parse-str
to parse xml. Can I get it to ignore newlines between tags? Ie removing the \n
in the :content
of the :foo
element below:
(xml/parse-str "<foo>\n<bar>42</bar></foo>")
=> #xml/element{:tag :foo, :content ["\n" #xml/element{:tag :bar, :content [”42"]}]}
This may seem like an obvious question, but anyone know best/fastest way to strip metadata from an object?
Thanks for the response @jr, though I think that still produces an empty map, as opposed to (meta obj) > nil
.
is there any lib for creating Maven plugins in clojure? The only interesting thing I found is in Zi
https://github.com/pallet/zi/blob/develop/src/main/clojure/zi/mojo.clj