This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-23
Channels
- # announcements (3)
- # architecture (10)
- # babashka (37)
- # beginners (69)
- # calva (2)
- # cider (10)
- # clerk (22)
- # clj-kondo (33)
- # cljdoc (44)
- # clojure (45)
- # clojure-conj (4)
- # clojure-denmark (7)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (4)
- # clojurescript (10)
- # clr (19)
- # conjure (1)
- # emacs (28)
- # events (1)
- # fulcro (1)
- # jobs (1)
- # joyride (1)
- # lsp (18)
- # malli (30)
- # membrane (3)
- # off-topic (23)
- # pathom (45)
- # portal (29)
- # proletarian (7)
- # rdf (15)
- # re-frame (21)
- # reagent (2)
- # releases (6)
- # remote-jobs (1)
- # reveal (6)
- # shadow-cljs (36)
- # slack-help (7)
- # sql (5)
- # tools-deps (3)
hey 👋 thanks a lot for malli, it’s very useful. We’re looking at unsing function inline schemas in our codebase and wondering about a few things: 1. what should I expect from the clj-kondo integration? Should I expect and error given the following spec & call
(mx/defn transact! [{:as system :keys [datomic]} :- [:map [:datomic some?]] tx-data :- sequential?]
,,,)
(transact! {} [])
2. is there a way to assert only the presense of certain keys in a map, without the some?
above? Can I maybe even https://cljdoc.org/d/metosin/malli/0.10.1/doc/readme?q=keys#destructuring?
3. when do I need to call mi/instrument!
? It seems I need to call it again after I change a defn
with inline function schemas, is that right?@U04V15CAJ that’s for the clj-kondo integration?
https://github.com/metosin/malli/blob/cfbc8eaa05bedb1e7e7b132d52bbf2e61b143f92/src/malli/dev.clj#L15
you need to make a few edits before it has an effect, to re-trigger clojure-lsp / clj-kondo
but calling the function with invalid args doesn’t error, only after I call (mi/instrument!)
again
I only have to re-evaluate the defn and then make 1 additional edit to re-trigger linting
re-evaluating the mx/defn
should automatically re-create clj-kondo configs when dev/start!
is running.
@U5H74UNSF — Do you mean that calling a function with mx/defn with the wrong args doesn’t immediately fail?
I had that problem, and fixed it by having the instrumentation call baked into the macro: https://github.com/metabase/metabase/blob/master/src/metabase/util/malli.clj#L53-L78
then it behaves like s/defn. I think there was talk of including somethng like this (mx/defn ^:always-check …)
but I havn’t kept up with it.
IF we are talking about adding options to mx/defn
, tho.
My wish list would have:
1. “always check args and return value.”
2. It’d be cool to have a way to say “just make the shell of a function, which takes the args, checks them against the schema, and returns a generated value from the schema.” I know it’s mechanically not difficult, just needs to be hooked up. Maybe I should make an issue.
I broke it into 2, since I’ve written #1 already. Had some open questions though. 1) https://github.com/metosin/malli/issues/823 2) https://github.com/metosin/malli/issues/824
Put together a PR for 1) here https://github.com/metosin/malli/pull/702/files#diff-08fdf5164d5d2562ba6f3e187911a9db8086c3d06a3d048cd8045818b2d960e5R94 main motivation at that point was for better cljs DX, which isn't needed anymore, but having a form that is always instrumented is definitely useful
Is it possible to compare schemas ?
No, I've looked into documentation trying to find something like equals. Thank you.
Shouldn't (mu/equals [:map [:foo [:maybe :string]] [:bar :some]] [:map [:bar :some] [:foo [:maybe :string]]]) be considered equal ?
if ordering matters, they are not equal. But I see the value in having a utility for deep-equals, ignoring order.
I was manually running mp/provide to infer the type to inject on reitit to get on the other side with some swagger generator to typescript, so a not positional equals would help.
IF we are talking about adding options to mx/defn
, tho.
My wish list would have:
1. “always check args and return value.”
2. It’d be cool to have a way to say “just make the shell of a function, which takes the args, checks them against the schema, and returns a generated value from the schema.” I know it’s mechanically not difficult, just needs to be hooked up. Maybe I should make an issue.