This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-08
Channels
- # announcements (14)
- # babashka (16)
- # beginners (15)
- # biff (15)
- # calva (48)
- # clj-kondo (42)
- # cljdoc (25)
- # clojure (18)
- # clojure-europe (75)
- # clojure-nl (1)
- # clojure-norway (19)
- # clojure-romania (1)
- # clojure-uk (10)
- # conjure (18)
- # core-typed (4)
- # cursive (16)
- # emacs (8)
- # fulcro (27)
- # graalvm (17)
- # honeysql (14)
- # hyperfiddle (9)
- # lsp (24)
- # missionary (5)
- # music (1)
- # nrepl (20)
- # off-topic (14)
- # re-frame (9)
- # reagent (34)
- # reitit (2)
- # releases (1)
- # shadow-cljs (19)
- # sql (16)
- # squint (9)
- # testing (2)
- # tools-build (10)
Is there, perchance, a defrecord
alternative with optional fields? e.g I can construct it with fewer fields, or I can dissoc fields from it, and it remains being of instance of the underlying class (and not a vanilla map)
Because defrecord basis fields are actually object fields, and those cannot be removed from an object, you would need a new field to indicate if a given field has been dissoc'ed or not
> Because defrecord basis fields are actually object fields, and those cannot be removed from an object, Yes, this aspect was making me hesitate. But perhaps there's some cool implementation out there.
I think maybe you could get away with some kind of sentinel value at best (nil is out, of course)
defrecord
allows you to assoc on additional fields. You can do:
(defrecord MyFoo [])
If a field is optional, just leave it out. Associng and dissocing unspecified fields will still return a Foo.
> (-> (->MyFoo)
(assoc :foo 42)
(dissoc :foo)
type)
user.MyFoo
brilliant, thank you š It's no issue to leave optional fields out, since there's some Malli validation going on anyway
You mean like bash environment variables? A child process cannot change the values of environment variables in a parent process. You can pass an environment of variable settings you wish to a new child process you create.
Some programs, e.g. āssh-agent -sā, have as their standard output a bash script that the calling bash can do āsourceā on.
But that thing with ssh-agent and similar programs only actually changes the calling bash process's environment variable values if you explicitly invoke them in a way that the calling bash uses source
somehow, e.g. source
ssh-agent -s``
I would suggest taking a look at https://github.com/lambdaisland/launchpad
you can introduce a shim that is amenable to that. grab the env and throw it in a map, and then an api that lets you set overrides and add to it. If you donāt reach out to the environment but this api you can āmutateā the environment
thereās https://github.com/weavejester/environ and i think we have a few (alter-var-root #'env/env assoc :mb-db-type "h2")
to achieve this in a bit hacky way but in tests and in some off code
thanks for the links. To give you a bit more background. I use aero
for configuration. Aero can reference env vars. However, I doubt that it will work with environ
.
Most times what one really wants is using JVM system properties instead
They play great with tools.deps/Lein aliases, with raw java
, with property files, can be set in runtime, etc
@U023LKF2PQV with aero you usually do not have to overwrite env vars - default values for env/envf readers or merging dev-time configs works better in my experience