Fork me on GitHub
#clojure
<
2021-04-20
>
Mark Wardle07:04:03

Hi all. Is it possible to use an alias in a git coordinate in deps.edn? This impacts the way I structure my projects and git repositories. I’m increasingly finding use of deps permits greater modularity - and increases my ability to use a single repository for different purposes - e.g. via aliases - so that repository can be used as a library or a standalone domain service. That’s instead of having two repositories ‘my-cool-library’ and ‘my-cool-server’, I have ‘my-cool-project’. This works really well. e.g. see my https://github.com/wardle/clods service - which can be run as a HL7 FHIR server or simply embedded as a library - and in the latter’s case not drag in dependencies. But, there’s one snag. What if I want to use some of the server code (e.g. some ring handlers) in another project? Is it possible to reference an alias when using a git coordinate? I cannot see that it is. So the options are 1. Build a maven package for the different aliases 2. Use separate code repositories ‘-library’ ‘-server’ . 3. Ask whether others might think referencing an alias (or aliases) to configure what is included in a git coordinate in deps.edn might be useful? Or am I doing this wrong?

Mark Wardle08:04:16

To explain: I’m working on assumption that the repository is business domain orientated - and the aliases are technology orientated. It means greater composability and ability to flex/adapt eg spin out a dependency of a wider project to its own managed service vs use as a library when starting out. So being able to slice and dice along what are orthogonal boundaries is helpful. For example, I am building a graph API across multiple repos - but the resolvers should logically be in the repo to which they relate - I combine the graph resolvers or I combine as libraries. But the core library shouldn’t drag in dependencies on graphs as that’s just one prism through which to view that domain. Having a tiny ‘xxx-graph’ repo is IMHO worse than a graph alias which switches on that “prism”.

borkdude09:04:16

There is a #tools-deps channel for this

👍 4
Mark Wardle09:04:37

Thanks! Didn’t see that. I’ll ask there.

restenb11:04:43

is there some standard HTTP request timeout built in to the ring-jetty-component, or underlying jetty server? i'm experimenting with some long lived requests, but the server (which runs jetty via @weavejester's ring-jetty-component) boots my requests before any timeout I've actually programmed in happens

jumar13:04:14

Nothing I know about. What exactly happens in your case?

restenb15:04:01

i'm reading clj-http docs on async requests and a bit unclear on whether sending a request with :async truewill still block the calling thread or not?

restenb15:04:35

experiments with sending many requests in a go block suggests it does, only 8 can be waiting at a time

restenb16:04:55

^ disregard this, it returns a CompletableFuturewhich is indeed blocking. i'll have to run this on a separate thread pool

hiredman16:04:11

it depends on how you use the CompletableFuture

hiredman16:04:28

you can attach callbacks to it instead of derefing it

didibus17:04:56

The docs on GitHub says it returns an Apache BasicFuture. Are the doc wrong or are you not using clj-http?

stopa20:04:23

Hey fam, qq — is there a more idiomatic way you’d suggest writing this:

(defn wrap-around [tokens i]
  (let [left-el-idx (dec i)
        right-el-idx (inc i)]
    (concat
     (take left-el-idx tokens)
     (list (list (nth tokens i)
                 (nth tokens left-el-idx)
                 (nth tokens right-el-idx)))
     (drop (inc right-el-idx) tokens))))

(comment
  (= (wrap-around '(neg 3 * 2 + 1) 2)
     '(neg (* 3 2) + 1)))

stopa20:04:54

(basically, given a list, i want to update a part of a list, to wrap, a range of inner elements)

noisesmith20:04:22

the code would be much more readable if you used [x y z] instead of (list x y z)

noisesmith20:04:16

(concat (take ...) [[(nth tokens 1) (nth tokens ...) (nth tokens ...)]] (drop ...))

seancorfield20:04:17

I think using split-at might help too?

seancorfield21:04:19

(defn wrap-around [tokens i]
  (let [[left right] (split-at (dec i) tokens)
        [l t r & right] right]
    (concat left [(list t l r)] right))))

❤️ 9
ghadi21:04:26

it's idiomatic to add a docstring

ghadi21:04:44

#1 recommendation

stopa21:04:46

oo, nice. Thanks team!

ghadi21:04:03

"update a part of a list" not semantic

👍 3
ghadi21:04:40

is this op specific to tokens or lists of anything?

stopa21:04:09

https://gist.github.com/stopachka/4957d20625f689a30df68c6108855e0b#file-play-clj-L66 ^ more context friend challenged me to write a “natural language calculator” of sorts in clojure. He thought our immutable data structs would make it harder to do…will show him >:)

👍 4
🧮 3