Fork me on GitHub
#clojure
<
2023-06-28
>
mmer10:06:28

Hi A simple question about running a set of functions :

(defn apply-all [data]
  (apply-role)
  (apply-objectgroups data)
  (apply-usergroups data)
  (apply-permissions data)
  (apply-users data)
  (apply-user-to-usergroups data))
What I am finding is the first one runs, the subsequent ones run but don't evaluate their internals and the last one runs completely. How do I get them all to run - internally they are calling rest calls?

magnars10:06:32

My suspicion is that your functions return lazy sequences, that are not realized since they are never inspected. This would happen if you're using map or for to perform side-effects, for instance. If that is the case, then doseq is a good option for iterating over side-effecting code.

☝️ 6
2
2
mmer11:06:02

Thanks that fixed it.

apbleonard19:06:13

You might prefer https://clojuredocs.org/clojure.core/dorun if you don't plan to use the sequences returned by doseq. It may not matter much in your case but where those sequences are large it makes a big difference. dorun doesn't "retain the head" of the sequence, so each iteration is used once and then dropped so it can be garbage collected efficiently. (I sort of feel using doseq without explicitly making use of the returned sequence should also allow each iteration to garbage collect well but that's much more difficult to reason about or prove!)

didibus19:06:12

Yes, dorun or run! are best when you want to iterate for side-effects only and don't use the return value at all

👍 2
magnars22:06:12

Please note that doseq does not have a return value.

👍 2
magnars22:06:10

> "Repeatedly executes body (presumably for side-effects) with > bindings and filtering as provided by \"for\". Does not retain > the head of the sequence. Returns nil."

didibus22:06:15

Right, I forgot. It goes: map -> run! doall -> dorun for -> doseq

didibus22:06:38

You can also avoid sequence functions altogether and use eager functions like: mapv reduce any of the transducer arity loop/recur

mmer07:06:10

That has been really helpful, I was completely unaware of most of those functions

apbleonard08:06:19

@U07FCNURX Thanks - I was mixing up doseq with doall picard-facepalm

😊 2
Kent Bull18:06:05

Where are some good libraries or templates for writing ReST APIs in Clojure? Connect to Datomic, store some records, pull some records, etc. Bootstrapping a greenfield project here.

Ben Sless19:06:30

jetty web server, reitit+malli for routing, web handling and schema validation, Component for lifecycle management, aero for configuration

apbleonard19:06:45

Not the smallest template or set of concepts to buy into but it could repay the investment? https://github.com/furkan3ayraktar/clojure-polylith-realworld-example-app

polylith 2
rads19:06:24

#biff is another option for a more full-stack template: https://biffweb.com/ Some of the built-in components rely on XTDB, but it wouldn't be that hard to modify to use Datomic instead It also uses jetty, ring, reitit, and malli

🏂 4
markbastian19:06:43

My Clojure North 2020 https://github.com/markbastian/clojure-north-2020’s final example uses REST/Swagger, Datahike (another datalog variant — would be easy to change to Datomic), Jetty web server, and Integrant to tie it all together.

nice 2
Kent Bull19:06:10

Cool, thanks guys.

Noah Bogart21:06:14

Probably more of a java question than a clojure question but just in case: I am writing a CLI program that attempts to read the deps.edn in the directory where the program is run. In manual testing (create a jar and then run it from various directories), it works, but I'd like to have an automated way to test that functionality. I see on Stack Overflow that there's no way to "cd" aka change the current working directory from within a Java process, but is there a clever way of saying in a test, "for the duration of this test/call, act as if the whole program is running in a temporary directory"?

Noah Bogart21:06:52

I have helper functions and macros that can create temporary directories and files, the issue is making the test runner think "i'm in this specific directory", so calling (io/file "deps.edn") sees the file in the temporary directory

isak21:06:58

Can you use with-redefs in the tests?

isak21:06:12

(redefining a function that you use to get the current directory)

Noah Bogart21:06:34

I could, but I was hoping for something slightly less brittle. Maybe that would be fine, just makes me feel like I'm playing with fire

👌 2
vemv21:06:10

The boring answer is to make pwd an argument. (System/getProperty "user.dir") can be understood as a "side cause", those are best pushed to the boundaries of your program

👍 2
Noah Bogart21:06:17

ah yeah, that makes sense. thanks

🍻 2
vemv21:06:27

Is there such a thing as a drop-in (saas?) Maven caching proxy? I have a tooling project which tests must hit Maven each time. Because it has many tests / multiplied by a CI matrix, I suspect the flakiness I'm seeing has more to do with rate limiting (unlikely to see for normal user loads) than anything else.

hifumi12322:06:00

The best I can think of is setting up your own maven “repository” by starting up a webdav server in a container and making dummy credentials that allows leiningen et al to GET, PUT, and MKCOL as it wishes

hifumi12322:06:48

at some point in time I had a webdav server as a private maven repository with apache2… if you’re interested, i can eventually dig up the configuration files. shouldn’t be hard to containerize it and run it in CI

vemv22:06:23

Interesting. the key part is that it should be a proxy, e.g. if artifact foo is not found, query it in Central / Clojars Perhaps such an offering doesn't exist...

phill23:06:57

You could set up an actual Maven caching proxy, such as Apache Archiva.

Alex Miller (Clojure team)23:06:46

There are several drop in proxies

Alex Miller (Clojure team)23:06:31

Sonatype Nexus, JFrog Artifactory, etc

☝️ 2
lread23:06:05

@U45T93RA6, I learned a bit, not much, but a bit, about Sonatype nexus as a cache https://github.com/clj-commons/pomegranate/issues/107

igrishaev07:06:31

Did you consider the :local-repo option in Lein (deps have a similar option)? There might be a special path on your machine that holds m2 artefacts, and you can install Clojure packages there. This folder would act like a cache. Not sure if it solves your problem, but just an idea.

igrishaev07:06:43

You can even share that folder in CI across various steps/builds, and save the traffic.

vemv14:06:58

Nice! @UE21H2HHD’s example seem much handy. Although I was surprised to find no good google hits for <Sonatype Nexus || JFrog Artifactory> + <circleci | github actions>

Alex Miller (Clojure team)14:06:25

github actions can be set up to use specialized Maven settings, which I presume could use a Maven proxy (although not sure how that works when using it on github). The github java action lets you easily set up Maven repo caching which is kind of the norm.