Fork me on GitHub
#clojure
<
2017-01-31
>
thomas.williams00:01:13

It seems simple enough, but my google-fu was not strong enough to find a reasoable solution

jr00:01:17

(into {} (map (fn [val] [(compute-index val) val]) (array-seq ary))
?

tanzoniteblack00:01:57

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)

thomas.williams00:01:38

That looks more reasonable, thanks

thomas.williams00:01:49

Though a question, map doesn’t seem to pass in the original index

thomas.williams00:01:58

is there a way to get that index in the function?

thomas.williams00:01:19

That was a dumb question

spacepluk10:01:30

hi, does anybody have experience with direct linking + proguard?

danielstockton14:01:56

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.

baritonehands16:01:41

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?

jr16:01:31

code sample?

baritonehands16:01:34

For more context, I'm trying to make a more performant clojure.java.data

baritonehands16:01:28

I'd like to support multiple key conversion functions, not just keyword

alexbaranosky16:01:47

add an options map as the last arg?

alexbaranosky16:01:04

then perhaps add a wrapper fn with two arities, to pass {} for the default case

baritonehands16:01:52

(defmethod to-clj :default [instance & {:keys [keep-coll keep-nil? key-fn] :or {keep-coll nil keep-nil? false key-fn identity}}]

baritonehands16:01:09

@alexbaranosky I did something like that, but the arguments quickly got out of hand

alexbaranosky16:01:10

that's not an options map, that's keyword args

alexbaranosky16:01:25

let me draw up an example

alexbaranosky16:01:12

(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)))

alexbaranosky16:01:31

not sure if that's "idiomatic", but it works

baritonehands16:01:04

Yeah that makes sense

alexbaranosky16:01:26

so if you have a ton of methods, the convert-to-date saves a lot of typing up arities, basically

baritonehands16:01:31

Is there a standard way to merge the provided options with the defaults, or just (merge default-opts opts)?

alexbaranosky16:01:39

>> "where very few of the defmethods need the options?" Maybe I misunderstood ... I was under the impression most methods wont care about the options?

alexbaranosky16:01:50

for the ones that care, you can just use clojure.core/merge

baritonehands16:01:03

And I will use (update :key ...) if I need to change one option as I call recursively

alexbaranosky16:01:44

update sounds like the wrong fn

alexbaranosky16:01:52

update is for changing values with a function

alexbaranosky16:01:17

assoc is for setting a value

baritonehands16:01:27

I need to set a value based off its previous value

challen17:01:47

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!

tjtolton17:01:15

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.

tanzoniteblack17:01:41

@tjtolton why not just use an alternative test runner like https://github.com/weavejester/eftest that executes tests in parallel?

tjtolton17:01:10

tanzoniteblack: that looks pretty awesome, actually

tjtolton17:01:31

does it use the same syntax for defining tests as core.test?

tjtolton17:01:38

well, I can find that out myself

tanzoniteblack18:01:10

the tests themselves are identically created as used by core.test

tjtolton18:01:03

hmm.. one difference is that eftest seems to do parallelism, but not async, so each test will block a thread.

tjtolton18:01:13

i guess virtual threads are kind of fine

tanzoniteblack18:01:38

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)

tanzoniteblack18:01:54

well, i/o bound and written in a non blocking way with core.async

tjtolton18:01:17

yeah, I think you're right.

tjtolton18:01:08

thanks, @U236LQYB0 this looks like a great option! its much better than what I was asking for.

tjtolton18:01:45

do you know anything about making lein test use eftest?

tanzoniteblack18:01:25

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

tanzoniteblack18:01:49

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

rauh18:01:43

How come nth is not implemented for repeat? I mean: efficiently, constant time.

neurogoo20:01:05

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.

candera20:01:18

No, all my audio was batch.

7h3kk1d20:01:20

Just from googling the source from https://github.com/jblomo/iceclient might be helpful.

7h3kk1d20:01:36

I know you’re not doing icecast but just to see the streaming.

candera20:01:43

I mostly wrapped the Java sound libraries.

candera20:01:49

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.

candera20:01:49

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.

neurogoo20:01:14

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

7h3kk1d20:01:38

Might make sense to use external streaming software and just configure it through clojure.

7h3kk1d20:01:45

I’m no expert though.

candera20:01:40

@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.

neurogoo20:01:47

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

candera20:01:11

:thumbsup:

grav21:01:33

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"]}]}

zalky22:01:24

This may seem like an obvious question, but anyone know best/fastest way to strip metadata from an object?

jr22:01:31

(vary-meta obj empty) ?

zalky22:01:49

Thanks for the response @jr, though I think that still produces an empty map, as opposed to (meta obj) > nil.

jr22:01:43

(with-meta obj nil)

zalky22:01:01

bingo, thx!

richiardiandrea23:01:57

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