@pmonks Hum, not that I know, you can make one yourself. That said, you could also consider using metadata to mark a namespace as pure or not, same on your functions.
Ya, I have no idea what you want this for, so you know best. Just saying it's an option as well.
Hm, that might be a disqualification for Heroku. Though I see the do offer separate DBs, including Kafka
Hmm is there no if-let
that takes multiple bindings?
no
you can destructure though and let multiple values out of that (while if-ing on the collection)
(if-let [{:keys [foo bar]} some-maybe-nil-map] ... )
the if is based on whether some-maybe-nil-map is nil
My code would be something like when-let [foo (get-foo) bar (get-bar foo)] …
You may just want some->
Yeah that doesn’t let me differentiate at-a-glance in the filesystem (my main intent here is to communicate to humans, not to the computer).
Hum... I guess it depends where the human is looking
But (defn ^:pure foo [] ...)
is pretty visible to a human
Same for: (ns ^:pure my-ns)
@st3fan I've been using https://github.com/ptaoussanis/encore which includes when-let plus other -let constructs for multiple bindings
Yep those could work, though neither qualify as “at a glance in the filesystem” mechanisms.
👋 hi all. Just wanted to introduce myself. I'm the co-founder of a startup in Canberra Australia that's building enterprise software on a clojure/script stack. key parts of our stack include datomic, keechma-next, sente and shadow-cljs. We're just starting out but over time I'd like to give back to the clojure community in various ways.
@st3fan https://github.com/Engelberg/better-cond exports a version of if-let
and when-let
that checks multiple bindings; I don't use them myself, but I do use the better/cond
macro that is useful when writing code that starts leaning right towards multiple indent levels.
Is there an idiomatic way to merge vector of maps so that some values for some keys are aggregated, but others are not? Something like
[{:a "1", :b :some-keyword, :c "x"} {:a "1", :b :some-keyword, :c "y"}]
would be transformed into
{:a "1", :b :some-keyword, :c ["x", "y"]}
I’ve been playing around a bit with merge-with
, but I can’t get it quite right.I wrote this for a colleague some weeks ago, you might find it useful https://gist.github.com/bsless/e76a6537907ad4eecd69dcb321318b95
it's not that pretty but it works:
(def data [{:a "1", :b :some-keyword, :c "x"} {:a "1", :b :some-keyword, :c "y"} {:c "z"}])
(apply merge-with (fn [m v]
(if (= m v)
m
(if (vector? m)
(conj m v)
[m v]))) data)
check the source code, it should be relatively simple to follow the code: https://github.com/clojure/clojure/blob/clojure-1.10.1/src/clj/clojure/core.clj#L3051
Thanks, I appreciate it 🙂
cheers 🙂
And thanks @ben.sless, that also looks useful 🙂
sorry, there is a bug:
(merge-with (fn [m v]
(if (vector? m)
(conj m v)
[m v])) {:a 1 :b 5} {:a 1 :b 3})
this will produce => {:a [1 1], :b [5 3]
which I think it's what you want
my foldmaps might even be overkill for your task, because you have only one "index". You can ofc just rip the indexing part out of it
you can just (reduce (map-combiner {,,}) ms)
Yeah, I’ll take a closer look. I like to understand code I use 🙂
Thanks guys 🙂
godspeed 🙂
anyone used googles artifact repository with clojure jars managed to upload but cant convince deps to checkout the jar
Thank you I’ll take a look at that one
help calling java method.
I'm looking at the source code for isa?
and I see the line:
(and (class? parent) (class? child)
(. ^Class parent isAssignableFrom child))
How can I call the isAssignableFrom
method from the repl? Do I need to qualify it with some java.this.and.that/isAssignableFrom
, or do I need to require
something into my repl? Here's the error I'm getting.
(. Number isAssignableFrom Long)
Syntax error (IllegalArgumentException) compiling . at (clojure-rte:localhost:51477(clj)*:318394:23).
No matching method isAssignableFrom found taking 1 args for class java.lang.Number
Oh no I need a YAML library
(.isAssignableFrom Number Long)
Sorry, realized that I wasn't actually answering your question, but the above should work nonetheless.
What is an idiomatic way to translate something like this to Clojure:
if (foo && bar) {
return;
}
if (something == false) {
return;
}
if (something_else) {
return
}
dosomething()
I’m trying to avoid inverting those conditions and creating a huge indented if pyramid
factor it out in a function and just use or
?
inverting expressions makes the decision logic hard to read
cond
?
I mean, this is already weird because it's a void method and those don't exist in Clojure
but:
(cond
(and foo bar) nil
(false? something) nil
(something_else) nil
:else (dosomething))
is effectively the same
maybe at that point I'd do:
(when-not (or (and foo bar)
(false? something)
(something_else))
(dosomething))
from what I can figure out i need to use a wagon in deps.edn but not finding anything online
{:mvn/repos
{"artifactregistry" {:url "<artifact-registry://europe-west2-maven.pkg.dev/production/test-maven>"}}}
I have added the above to deps.edn but seems it does not understand artifact-registry from what i can work out it needs to launch something to add that protocol format, not finding any details on how to go about that how ever 😞I have read a bunch of stuff about spec, but still don't understand when I am supposed to use it. Should I spec every function definition? What about the performance costs of that? Also, spec suggests that the keywords I use in hash-maps should be namespaced, is that a standard practice? I haven't seen that recommendation anywhere else I think, besides fulcro docs maybe.
I believe it is fairly common for those who use spec to use it in production only to check inputs at the boundaries of major subsystems, e.g. for requests from outside of one piece of software, or perhaps sometimes between major subsystems. The run-time cost can be mitigated by being selective. For test time, it can be worth the extra checking time to enable checking at many more places. For testing individual functions or groups of your functions, generative testing, e.g. with test.check can help provide good test coverage at test time.
Is this one of the articles you read on spec? It is written by a long time Clojure developer who has used spec in their production Clojure code for several years now.
seems mixing lein and deps.edn using this plugin https://github.com/lurodrigo/lein-artifact-registry/ and then using lein-tools-deps to read the deps.eddn file seems the dependencies are merged would be nicer to do this all in deps file if its possible ?
No, I don't think I have read that one, thank you!
So I should define some of the specs inside test namespaces then, if I want them to run during test time?
I believe some people create completely separate namespaces for spec definition, so that they can be loaded only when desired. By doing that, they can be loaded at test time, true, but they can also be loaded at production time without loading in all of the test code.
I see, makes sense, thank you. I'll read the post and ask more questions if I have any.
Probably the only reason the author didn't answer your question before I did is because it is very early Pacific time right now 🙂
clj does not have support for custom wagons/transporters right now
filing a request at https://ask.clojure.org would be a great place to make a votable thing that we can track
the underlying tools.deps lib does support custom procurers but does not specifically support custom transporters or wagons, but that is possible to add
see my thread above
okay thanks for the info, i was about to ask on reddit 🙂 I will post on ask.clojure as suggested
although ask only seems to let you register with github 😞
thanks anyway, i will go back to using lein for now
perhaps i will post on reddit as well just so there is some history 🙂
do I get it right that clojure.core.async/go
and future
have the exact same purpose, except for their respective thread/pool subtelties?
and then, considering the error handling overhead that comes with future
, I should use go
if I don't care about threading boundaries?
I'd say they have entirely different purposes actually but if you're not doing any async ops, I'd use future
well posting there will cause nothing to change if that is your goal
what do you mean, "not doing any aync ops"?
http://ask.clojure.org is where we collect and determine the priority of requests
parking ops like >! <! etc
my actual current project uses futures, but I never dereference them (their purpose is network side-effects)
you should not do blocking io operations in go blocks
and I'm really torn between keeping them and using core.async
as it is a fixed size pool and you can lock it up that way
it does not seem like you have a use case that matches core.async afaict
I see
and using go blocks with futures inside for the IO parts, would be overkill?
I guess I really don't like the errors popping in places totally different from the actual crash place (I use try/catches with every futures), and naively believe that go blocks would somehow solve the problem
yeah, it would not help you with that
it does not seem like core.async solves any problem you have and likely introduces new ones :)
😄
ok let's avoid that pitfall then, thank you!
how come it only has github sign up seems flawed if its the main way to track stuff
will have another look perhaps i missed sign up button
it is github only right now
most devs have a github acct so that has not generally been an impediment so far. if you don't have one, I can file a request for you there
that would be very helpful, I am also a bit suspect of the legitimacy of that site as it has various issues or perhaps its just very new
not a site I have come across in the clojure eco system previously anyway
github?
posting on reddit for posterity anyway as i will probably need the work around again
no ask.clojure
https://ask.clojure.org is the official clojure Q&A site run by the core team, of which I am a member. I run it.
I'm also the primary dev on tools.deps and clj
oh I did not knwo that
is it supposed to look like that on a desktop ?
feels like a mobile version and the x is mis aligned
that does look like the mobile layout - but it's a responsive layout so looks different as you widen it
I get column if i widen it and a categories box, not try to offend just thought i would point out if there is an issue
good work on tools.deps anyway I actually really like it as a build tool for managing my projects
Hi, I dont know if is a bug, but last week, this work like that:
> (format "%.3f" 2.0)
"2.000"
Now the same thing is giving to me:
> (format "%.3f" 2.0)
"2,000"
@contato509 that looks like something that would be controlled by the LOCALE
environment variable
oops - not LOCALE itself, but the locale system, that uses LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC etc. (on linux at least)
Was that thanks
I logged this at https://ask.clojure.org/index.php/9804/add-support-for-google-artifact-registry-tools-deps-and-clj and https://clojure.atlassian.net/browse/TDEPS-172 btw