This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-26
Channels
- # announcements (4)
- # babashka (8)
- # beginners (75)
- # calva (26)
- # cider (33)
- # circleci (5)
- # clojure (36)
- # clojure-dev (2)
- # clojure-europe (25)
- # clojure-nl (4)
- # clojure-spec (38)
- # clojure-uk (47)
- # clojurescript (15)
- # cloverage (2)
- # conjure (64)
- # core-async (41)
- # cursive (13)
- # data-science (2)
- # datalog (16)
- # datascript (22)
- # datomic (9)
- # duct (2)
- # emacs (81)
- # figwheel-main (1)
- # fulcro (4)
- # jobs (2)
- # jobs-discuss (29)
- # kaocha (3)
- # meander (11)
- # membrane (21)
- # off-topic (1)
- # portal (1)
- # re-frame (1)
- # reitit (1)
- # releases (2)
- # remote-jobs (31)
- # shadow-cljs (26)
- # specter (5)
- # sql (26)
- # tools-deps (19)
- # vim (12)
heh, just discovered that clj
does not work if your path has an emoji in it. such a show-stopper bug!!
Reminded me https://askubuntu.com/questions/938606/dwarf-fortress-starting-during-apt-get-upgrade
Hi all. Clojure beginner and first-timer here š First time using Slack as well š ... I have some paranormal activity when trying some core.async stuff and I am going insane...is here a good place to ask for a second pair of eyes & brains to try to find out what is going on?
both #beginners and #code-reviews are good channels for that
General question about clojure.spec.alpha/fdef and testing that with clojure.spec.test.alpha/instrument - are there conditions under which the instrumentation gets bypassed? I am able to trip the spec validation from the REPL, but when the fn is called in the context of a unit test (rather deep in the call stack, mind you) I can not get the validation to fail
I have run into this problem before. If you have a function that is fdef, and then in the same namespace lower, you have a map of say {:keyword fn}
to serve as a dispatch, then the reader captures the uninstrumented function. By the time it get instrumented, it is too late.
even if I put the instrument call in the unit test itself
@cpmcdaniel vars are boxes, and spec's instrument replaces the content of that box. If something has grabbed the value inside the box before instrumentation replaces it, you could observe the (non) effect that you're (not) seeing
the other reason why you may not see it is when using AOT-compiled direct linking, but I doubt that's the case here
direct linking calls directly and thus does not go through the var and does not see instrumentation
I'm once again feeling stupid (not enough sleep) what's the best/simplest way to sort vector of nested maps, e.g:
[{:foo [{:bar [{:zap 4}]}]}
{:foo [{:bar [{:zap 3}]}]}
{:foo [{:bar [{:zap 2}]}]}
{:foo [{:bar [{:zap 5}]}]}
{:foo [{:bar [{:zap 1}]}]}]
want them sorted by :zap
, but it has to work for maps with arbitrary level of nesting"arbitrary" level? So you really don't know what shape the data is, but it will always have a single :zap
key in there somewhere @ag?
I think I need a fn of this signature (sort-by-nested coll & ks)
where I would call it for example like this: (sort-by-nested my-list :foo :bar :zap)
(sort-by #(get-in % [:foo :bar :zap]) ...)
(although your example above has vectors too)
But whatever the path to :zap
is, that's what you need in your sort-by
accessor function.
ah, @seancorfield I think you're on the right path, I'm gonna play with it. Thank you
ended up doing something like this:
(defn get-in*
[m ks]
(reduce (fn [acc k]
(cond
(map? acc) (get acc k)
(coll? acc) (->> acc
(keep #(get-in* % [k]))
flatten
seq)
:else (reduced acc)))
m
ks))
(sort-by
(fn[x]
(first (get-in* x [:foo :bar :zap])))
[{:foo [{:bar [{:zap 4}]}]}
{:foo [{:bar [{:zap 3}]}]}
{:foo [{:bar [{:zap 2}]}]}
{:foo [{:bar [{:zap 5}]}]}
{:foo [{:bar [{:zap 1}]}]}]
)
vectors are associative, so you can use indices as keys. for eg:
(sort-by
#(get-in % [:foo 0 :bar 0 :zap])
[{:foo [{:bar [{:zap 4}]}]}
{:foo [{:bar [{:zap 3}]}]}
{:foo [{:bar [{:zap 2}]}]}
{:foo [{:bar [{:zap 5}]}]}
{:foo [{:bar [{:zap 1}]}]}])
I have a config.edn
file (env variables) in the root of my project (the root is not on the classpath because itās not specified). As a result, the following wonāt work:
(io/resource "config.edn") ; => nil
But this would work
(io/as-url (File. "config.edn")) ;=> #object[java.net.URL 0x6e4e60f5...]
If one wanted to continue using resource
over the File.
solution, I would have to add the root "."
to the classpath. Is there a downside to adding the root to the classpath? or would the preference be to opt for io/resource
and just move config.edn
to the resources
dir?it depends. typically, config belongs outside of the program/jar so that it can be specified at runtime. what kind of config is this?
My config.edn
would be configuring all aspects of the app itself e.g. secret keys, ports, database URI etc. The secrets themselves would live outside the config.edn
and the config.edn
pulls them in. (iām using Aero)
i'm not sure familiar with Aero, but if config.edn
is just a template for loading config values (ie. it will be the same for everyone), then putting it on the resource path seems fine. otherwise, I would load it at runtime based on some user provided path
@tkjone I too use aero
, and what Iāve tended to do is have a ādefaultā config.edn
in a resources sub-folder (which is part of the classpath), but then allow an alternative config.edn
file to be specified on the command line. The default is only used if nothing is provided on the command line, and generally contains aero
instructions to just read from environment variables.
Hereās an example:
ā¢ Default config.edn
, showing delegation to env vars: https://github.com/pmonks/futbot/blob/main/resources/config.edn
ā¢ config.edn
for my production environment: https://github.com/pmonks/futbot/blob/main/heroku-config.edn (note mix of env vars and āhardcodedā values)
ā¢ Code that reads command line and determines which config.edn
to read: https://github.com/pmonks/futbot/blob/main/src/futbot/main.clj and https://github.com/pmonks/futbot/blob/main/src/futbot/config.clj#L50-L53 (note that I also use mount
for state management, so itās where the config.edn
gets managed at runtime).
Not saying itās the ābestā or even the ārightā way to do this mind you, but itās worked well enough for me in a variety of apps over the last 5 years or so.