clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2020-10-19T04:36:58.328300Z

Hello, how to map java's try-with-resource statement in clojure? thanks.

seancorfield 2020-10-19T04:46:18.329100Z

@kimi.im It depends on the type of resource, but with-open is used with anything "closable".

👍 1
2020-10-19T09:14:52.330700Z

I'm trying to use juxt with two java function invocations (map (juxt .foo .bar) coll), however this doesn't work. Is there a nicer way then just fully expanding it to (map #([(.foo %) (.bar %)]) coll)?

2020-10-19T09:29:53.330900Z

Have a look at memfn macro

p-himik 2020-10-19T09:30:07.331100Z

Was about to mention it. :) And that expansion wouldn't work anyway.

2020-10-19T09:33:35.331300Z

(map (juxt #(.foo %) #(.bar %)) coll) should also work

2020-10-19T09:33:52.331500Z

clojure’s documentation suggesting to use that form instead of memfn macro

2020-10-19T09:35:29.331900Z

@delaguardo perfect! exactly what I was looking for, thanks!

svt 2020-10-19T09:37:54.332600Z

Anyone knows how to convert com.rabbitmq.client.impl.LongStringHelper$ByteArrayLongString into clojure string?

2020-10-19T09:40:06.333200Z

(String. your-byte-array-here) ?

svt 2020-10-19T10:13:48.333600Z

:cause No matching ctor found for class java.lang.String

2020-10-19T10:16:00.333900Z

and what is the type of argument?

svt 2020-10-19T10:32:36.334100Z

ByteString Array

svt 2020-10-19T10:33:58.334300Z

I’m getting it from queue message property header I’m using [com.novemberain/langohr "5.1.0"]

2020-10-19T10:34:00.334500Z

Is it something from your codebase? I can’t find such java class

2020-10-19T10:36:08.334700Z

try use type function it will return fullyqualified class name

svt 2020-10-19T10:46:31.335300Z

Type: com.rabbitmq.client.impl.LongStringHelper$ByteArrayLongString

svt 2020-10-19T10:47:16.335500Z

#object[com.rabbitmq.client.impl.LongStringHelper$ByteArrayLongString 0x33be57eb {"foo": "bar"}

svt 2020-10-19T10:47:31.335700Z

This is the type I’m getting

2020-10-19T11:01:33.336100Z

aha! try this (String. (.getBytes your-byte-array-long-string))

2020-10-19T11:02:17.336500Z

or even better (str your-byte-array-long-string) because there is toString method implemented for that type of data

💯 3
emccue 2020-10-19T18:49:43.341900Z

(juxt (memfn foo) (memfn bar))

simon 2020-10-19T20:39:05.346500Z

How do you perceive inline tests in the attr-map compared to other test methods such as with-test or deftest? I see the advantage that tests are as near to a function as they can be, ie. writing tests is easy. On the other hand, a file can grow very quickly in length and the name and signature of a function is buried between tests and function code. What's the opinion of professional Clojure coders? Do you always use a specific way (in certain scenarios)?

2020-10-19T20:43:51.347Z

I perceive them to be deprecated

2020-10-19T20:45:11.347900Z

tests in the attribute map are a thing that predates clojure.test as a library, and not something that belongs in modern code (anything written in the last 10 or so years)

lukasz 2020-10-19T20:46:36.348300Z

I don't think I've ever seen them in the wild :thinking_face: (tests in the attribute map, that is)

2020-10-19T20:47:49.349Z

attribute map is really the right thing to call it, attr-map is just want the docstring for defn calls it

2020-10-19T20:48:03.349300Z

it is really just metadata that gets put on the var

2020-10-19T20:49:28.350200Z

it is confusing because regrettably clojure.test also stores tests in metadata, but that semantics are different

2020-10-19T20:50:21.351Z

there is clojure.core/test which is the primitive thing for running a test in the metadata system that predates clojure.test

2020-10-19T20:51:04.351900Z

is presumes that tests failures will throw an exception, which clojure.test doesn't, and it only can run tests on a single var

simon 2020-10-19T21:18:50.352400Z

Thanks! I've seen it in another project but think I'll move to deftest then 😉