Hey guys. Iβm hand-rolling my own solution for a static site generator. Now Iβd like to have multilingual support, Iβm wondering what the best way to go about that is. I assume Iβll have to deal with routing eventually, using something like bidi or reitit. What other things should I consider in order to keep things neat? https://gitlab.com/wildwestrom/cljs-tailwind-static/-/tree/personal-site
Hi everyone, I'm looking for something I encountered before (but can't think of the right search terms). What is the website that analyses clojure code and helps you to "fill in the blanks" of the code using core.logic
(?) which is based a haskell's implementation
Something simliar to lein kibit
it helps to fill in the blanks based on the output
not core.logic based, but a similar idea, https://borkdude.github.io/re-find.web/
Hosted here: https://borkdude.github.io/re-find.web/
Thanks! π
I haven't seen this before, this looks quite useful! I also like the way the examples slowly cycle, that is a really nice touch that I have not seen before.
Thanks :)
Team I am trying to add all the name from database to vector and I wrote below code
(let [name (.next list-of-statement)
v (conj [] (->> name (.getName) (.toString)))]
v)
it returns nil because of immutability
how can I get all the names into vactor from database
this code canβt return nil because (conj [] β¦)
will return a vector
ya empty vector,, how can I append values?
empty vector or [nil]
?
Even (conj [] nil)
returns [nil]
, i.e. a vector with one element (which is nil
), so I don't see how that expression you gave can possibly return an empty vector.
i want to add each value of (->> name (.getName) (.toString))
is it possible that this peace is working in bigger context? Iβm expecting you are trying to append an element to vector in a loop
is list-of-statements an iterator? If so you could use iterator-seq
to turn it into a seq which is a lot easier to work with.
Then you can use more standard/idiomatic clojure.
(do (defn db-values [] (iterator-seq all-db-vals-iterator))
(defn db-value-name [db-value] (-> db-value (.getName) str))
(defn db-value-names (->> (db-values)
(map db-value-name))))
Is list-of-statement
a Java Iterator object?
(recur (.listStatements name) giving me infinite object
yes @andy.fingerhut
See comment above about iterator-seq
which looks like good recommendation
Hi there. Can anyone give me a recommendation on what good mock/spy/stub testing library to use in Clojure/Script? Thanks in advance.
Did a quick googling and there's https://github.com/alexanderjamesking/spy but I'm just wondering what other good library I might miss out on π
You can also use with-redefs fn's from the standard library to mock out functions I do this in tests to avoid a db hit and return the rows I need for my test if your not aware of these functions.
Good day. I'm curious is there any guide about the argument position convention of clojure.core? I know some excerpts are: β’ Object as the first argument β’ Sequence as the last argument But every time I confuse where to put a numeric argument and also the last bullet not 100% truth.
some info about that topic - https://groups.google.com/u/2/g/clojure/c/iyyNyWs53dc not complete answer thou
the best way (imho) to get advantage from mocking/stubbing/spying is to make such ability first-class citizen in your application. libraries for dependency injections will help a lot there. You could have a look at integrant for example.
thank you
Thanks guys. I just need a way to do some simple testing for a small project I'm working in. At this scale I don't think I'd need something like Integrant, but thanks regardless π
Hopefully a quick one: Is there a usual approach for mocking a function to first throw an exception and then return something else? I'm trying to test a catch clause. In mockito I would have done something like andThen ...
like the first invocation would throw and subsequent invocations would return a value?
yes, that's what I'm doing in this particular case.
But having a pattern for returning one value, then another, etc., would be useful. The thing I'm mocking is making a REST call and returning the response, so it's not pure.
In another project, I did this with an atom holding a list and then popped them, but I must have done it wrong, because it's flaky. I'm hoping someone has a tried and true pattern.
Or it's just a feature of clojure.test I'm missing, and I don't have the right terms to google.
clojure test doesn't have any mocking functionality. its just assertions and such. if you're single threaded its possible to use with-redefs
and temporarily replace things with functions that do what you want. if you've got a system engineered where you construct a system graph, you could construct it with subsystems that do what you want
For mocking out REST calls, I use wiremock
a bit like this https://github.com/kelveden/clj-wiremock
Ah, yeah, that's what I use in Scala (the Java version of that). I always forget I've got the whole JVM world to draw on...
indeed, tis a beauty π
(wmk/with-stubs
[{:req [:GET (str "/tenant/v1/" rsc-tenant-id)] :res [200 {:body (utils/map->string {:tenantCode rsc-tenant-code})}]}]
(->> (generate-email-payload rsc-investigations rsc-tenant-code 12 app-config)
(expect (assoc rsc-email-configuration :body email-body))))))
bit like that π
Right, so I can make the first attempt return some non-200 (404) and then return a 200. Got it. Looks like what I want. Thank you!
yup
Is there a CLJ(S) library out there to make and subscribe to cursors from an atom?
there's no access to the jvm from scala?
Maybe relevant https://github.com/tonsky/rum#cursors
Yes, of course, but Clojure is so different that it just doesn't occur to me as easily. I just forget!
Is there a good way to make a transit api request from the CLI?
I have a list of dictionaries as such:
[{:id 1 :key 1 :value 1}
{:id 1 :key 0 :value 0}
{:id 2 :key 1 :value 1}
{:id 2 :key 0 :value 0}]
and id like to group this list by id as such:
[{:id 1 :attributes [{:key 1 :value 1} {:key 0 :value 0}]}
{:id 2 :attributes [{:key 1 :value 1} {:key 0 :value 0}]}]
This wouldnt be too hard in python but im scratching my head for how to write this in clojure π
clojure.core/group-by or clojure.set/index
thanks! will go do some doc reading π