This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-22
Channels
- # 100-days-of-code (1)
- # beginners (51)
- # carry (1)
- # cider (10)
- # clojure (71)
- # clojure-conj (4)
- # clojure-dev (9)
- # clojure-italy (3)
- # clojure-nl (2)
- # clojure-russia (8)
- # clojure-uk (16)
- # clojurescript (42)
- # cursive (4)
- # datomic (2)
- # emacs (8)
- # figwheel-main (7)
- # fulcro (20)
- # hyperfiddle (5)
- # jobs (2)
- # off-topic (16)
- # om-next (4)
- # onyx (9)
- # powderkeg (1)
- # re-frame (8)
- # reagent (17)
- # reitit (41)
- # robots (6)
- # rum (1)
- # shadow-cljs (54)
- # testing (3)
- # tools-deps (19)
Is clojure.core/merge
supposed to be used with non-maps, please? It's documented for maps as merging and replacing repeated keys with the last (rightmost) present value. For non-maps it seems consistent but non-obvious:
(merge [1] [2 3] [4 5])
evaluates to [1 [2 3] [4 5]]
.
Wouldn't you expect [1 2 3 4 5]
?
Admittedly, unsure what I'd expect with sequences, as:
(merge '(1) [2 3] [4 5])
gives ([4 5] [2 3] 1)
,
(merge '(1) '(2 3) '(4 5))
gives ((4 5) (2 3) 1)
.
Ah, that would make it like concat
. Hence the difference. But what's the meaning/goal of merge
with sequences?
Vectors are keyed by index
But merge works as if by repeated conj iirc what the docstring says
Thank you.
Does anyone have recommendations of github reagent tutorials? I owuld prefer samples of many mini projects that I can use as starting ground for my apps. It seems that the tooling and library integration is hardest to me.
Is there anything like Spring for Clojure? I need a IOC Container so that I can inject all dependencies (db, logger) into my backend api.
@grierson don’t know if this is exactly the same use case, I skipped the whole Spring thing
@grierson it depends what you want to do, limunus is comparable to spring boot, let's you start quickly
how might i go about reading and writing to/from a file in the same directory as my uberjar? i need to read, store, and update some simple config that's generated at runtime.
hmm. i can spit/slurp from outside the jar, but the file paths are relative to the directory from which i've run the command to launch the jar. i think i can solve that by supplying some shell scripts to launch the app.
@joshkh (System/getProperty "user.dir")
gives you the directory that the app is running from
I was just casually strolling through the leiningen ring plugin source code and found this: https://github.com/weavejester/lein-ring/blob/be43e45b8648f9fe2c758b1d27cae0a59eafa9d3/src/leiningen/ring/jar.clj#L30
(if (#{:all [:all]} aot-list) ...)
can someone explain to me what #{:all [:all]}
does? I know it creates a set of a keyword and a vector of the same keyword, but what does it do in the if
?
sets are also functions. when called with an argument they return the argument only if it's present in the set. in other words, "does this set contain the thing i'm passing to it?"
(#{:a :b :c} :a)
=> :a
(#{:a :b :c} :d)
=> nil
(some? (#{:a :b :c} :a))
=> true
@azzurite other data structures are also functions. for example, map this map over a vector of keywords, which are also functions:
(map {:a 1 :b 2 :c 3} [:a :b :c]) => (1 2 3)
to answer your question directly, do the true thing if aot-list
is equal to either :all
or [:all]
Okay I just think I got confused because aot-list
is weirdly named then, as it's not necessarily a list
agreed. it'd have to be a vector of one thing. i've run into situations in which i collect values that under certain circumstances end up being a list of one, so i can understand. like using (cond-> [] ...)
to conj some configuration.
@azzurite :aot-list
is normally a vector of the namespaces you want lein
to compile "ahead of time", e.g., [some.namespace some.other.namespace ..]
but there's a special value of :all
meaning "compile everything". However, some folks mistakenly wrapped it in a vector [:all]
so lein
is just allowing both forms here.
(and :aot-list
can be just a single namespace anyway :aot program.core
)
Again, for convenience so you can omit the [
.. ]
when you only want one namespace compiled, instead of being forced to write :aot [program.core]
I'm using ring/compojure for the first time and I'm a little confused about middleware. Is it just for altering the request/response or can it be used to return a response? For example, I have to validate a payload before it's converted to edn. I'm currently using the wrap-json-body
ring middleware to convert the payload to edn. Can I create middleware that validates the payload before the wrap-json-body
middleware runs, but if it's not valid, return a response from the validate middleware and short circuit the pipeline?
I suppose I could write a middleware function that validates the request and adds a flag to the request to say if it's invalid, so the handler can check this and return an appropriate response? I was initially confused because I was thinking the middleware should return a response if it's invalid, but that's not the responsibility of middleware afaik.
(fn [handler] (fn [req] (if (something req) (handler req) {:status 500 :body "error"}))
something like that
@brandon.ringe you can also enhance the response that some other handler returned:
(fn [handler] (fn [req] (let [resp (handler req)] (assoc resp :body "altered body"))))
Hi, I have a question about web apps, coming from the python world. In python, the parallelism and async request handling is apparent - you are pretty much required to run your app with an async app server (gunicorn, uwsgi...). I'm using http-kit for websockets, which shows you can do 600k (!) connections - http://http-kit.org/600k-concurrent-connection-http-kit.html . Clojure has way (way) more first class support for async stuff, so where is that parallel/async stuff in the stack? Is it enough to say "http-kit is handling it, don't worry about it"? Should I be using some java application server (tomcat, jboss, etc)? I'm just not clear exactly where the parallelism is in the http-kit stack (if you can even call it a stack...). Thanks very much in advance for any answers, or links to where I can just read this stuff for myself.
Http-kit is your "async app server". I mean it says on the main site http://www.http-kit.org/index.html itself: "HTTP Kit is a ... HTTP .../server for Clojure.
cool - just a little jarring coming from python, where that's a decision you have to make (how to support more than one req at a time)
do all clj app servers behave the same way? do they handle each request in a Thread? sorry for the simple questions, i haven't gotten the proper google query together to find exactly what i'm looking for