Fork me on GitHub
#beginners
<
2021-02-17
>
West05:02:41

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

zackteo08:02:01

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

zackteo08:02:22

Something simliar to lein kibit it helps to fill in the blanks based on the output

phronmophobic08:02:28

not core.logic based, but a similar idea, https://borkdude.github.io/re-find.web/

robertfw10:02:17

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.

zackteo08:02:51

Thanks! 🙂

popeye11:02:24

Team I am trying to add all the name from database to vector and I wrote below code

popeye11:02:25

(let [name (.next list-of-statement)
            v (conj [] (->> name (.getName) (.toString)))]
        v)

delaguardo11:02:13

this code can’t return nil because (conj [] …) will return a vector

popeye11:02:45

ya empty vector,, how can I append values?

delaguardo12:02:38

empty vector or [nil]?

andy.fingerhut12:02:39

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.

👍 1
popeye12:02:20

i want to add each value of (->> name (.getName) (.toString))

delaguardo12:02:27

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

Daniel Stephens12:02:10

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

andy.fingerhut12:02:16

Is list-of-statement a Java Iterator object?

popeye12:02:22

(recur (.listStatements name) giving me infinite object

andy.fingerhut12:02:11

See comment above about iterator-seq which looks like good recommendation

popeye11:02:39

it returns nil because of immutability

popeye11:02:51

how can I get all the names into vactor from database

aratare13:02:34

Hi there. Can anyone give me a recommendation on what good mock/spy/stub testing library to use in Clojure/Script? Thanks in advance.

aratare13:02:13

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 🙂

oly14:02:13

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.

delaguardo14:02:45

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.

aratare16:02:42

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 🙂

Illia Danko14:02:16

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.

delaguardo14:02:10

some info about that topic - https://groups.google.com/u/2/g/clojure/c/iyyNyWs53dc not complete answer thou

Eamonn Sullivan17:02:31

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

dpsutton17:02:49

like the first invocation would throw and subsequent invocations would return a value?

Eamonn Sullivan17:02:17

yes, that's what I'm doing in this particular case.

Eamonn Sullivan17:02:03

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.

Eamonn Sullivan17:02:39

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.

Eamonn Sullivan17:02:21

Or it's just a feature of clojure.test I'm missing, and I don't have the right terms to google.

dpsutton17:02:19

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

dharrigan17:02:29

For mocking out REST calls, I use wiremock

Eamonn Sullivan17:02:29

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

sova-soars-the-sora18:02:29

there's no access to the jvm from scala?

Eamonn Sullivan18:02:04

Yes, of course, but Clojure is so different that it just doesn't occur to me as easily. I just forget!

dharrigan17:02:40

indeed, tis a beauty 🙂

dharrigan17:02:45

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

dharrigan17:02:49

bit like that 🙂

Eamonn Sullivan17:02:33

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!

mruzekw17:02:52

Is there a CLJ(S) library out there to make and subscribe to cursors from an atom?

kvlt19:02:03

Is there a good way to make a transit api request from the CLI?

chaow20:02:20

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 😅

hiredman20:02:29

clojure.core/group-by or clojure.set/index

chaow20:02:52

thanks! will go do some doc reading 🙂