Hello, how to map java's try-with-resource statement in clojure? thanks.
@kimi.im It depends on the type of resource, but with-open
is used with anything "closable".
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)
?
Have a look at memfn
macro
Was about to mention it. :) And that expansion wouldn't work anyway.
(map (juxt #(.foo %) #(.bar %)) coll)
should also work
clojure’s documentation suggesting to use that form instead of memfn macro
https://clojure.org/reference/java_interop#_alternative_macro_syntax
@delaguardo perfect! exactly what I was looking for, thanks!
Anyone knows how to convert com.rabbitmq.client.impl.LongStringHelper$ByteArrayLongString into clojure string?
(String. your-byte-array-here)
?
:cause No matching ctor found for class java.lang.String
and what is the type of argument?
ByteString Array
I’m getting it from queue message property header
I’m using [com.novemberain/langohr "5.1.0"]
Is it something from your codebase? I can’t find such java class
try use type
function
it will return fullyqualified class name
Type: com.rabbitmq.client.impl.LongStringHelper$ByteArrayLongString
#object[com.rabbitmq.client.impl.LongStringHelper$ByteArrayLongString 0x33be57eb {"foo": "bar"}
This is the type I’m getting
aha!
try this (String. (.getBytes your-byte-array-long-string))
or even better (str your-byte-array-long-string)
because there is toString method implemented for that type of data
(juxt (memfn foo) (memfn bar))
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)?
I perceive them to be deprecated
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)
I don't think I've ever seen them in the wild :thinking_face: (tests in the attribute map, that is)
attribute map is really the right thing to call it, attr-map is just want the docstring for defn calls it
it is really just metadata that gets put on the var
it is confusing because regrettably clojure.test also stores tests in metadata, but that semantics are different
there is clojure.core/test which is the primitive thing for running a test in the metadata system that predates clojure.test
is presumes that tests failures will throw an exception, which clojure.test doesn't, and it only can run tests on a single var
Thanks! I've seen it in another project but think I'll move to deftest
then 😉