This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-21
Channels
- # announcements (10)
- # aws (10)
- # babashka (23)
- # beginners (111)
- # biff (8)
- # calva (25)
- # clj-kondo (9)
- # cljsrn (4)
- # clojure (72)
- # clojure-belgium (6)
- # clojure-europe (50)
- # clojure-germany (2)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-uk (1)
- # datahike (3)
- # emacs (10)
- # graalvm (19)
- # graphql (3)
- # juxt (7)
- # kaocha (9)
- # malli (23)
- # nbb (20)
- # pathom (17)
- # pedestal (6)
- # polylith (11)
- # portal (8)
- # remote-jobs (3)
- # shadow-cljs (18)
- # sql (3)
- # tools-deps (20)
Hi guys, how can I repeat an element of a tuple one or more times? E.g. I'd like to have a tuple: [:tuple :int :string] and only the string part should occur one or more times. When I try :repeat or anything, the strings get wrapped into a vector. Or is there a better way to get a heterogeneous list like [12 "a" "b" "c" ...]?
Ah, thank you very much!
Is there a way to extend a :multi
like how clojure.spec
allows you to extend a multispec
?
So far I found that all the keys of the :multi
need to be in the body at definition. I would like to add entries later.
With a mutable registry and some hackery I can add entries, but it is not very clean
I’m looking for something like this where I can register the dispatch type outside of the multi
(let [schema [:schema
{:registry {:x [:map [:hello :int]]}}
[:multi {:dispatch (fn [x] [:ref (:type x)])}]]]
(or (->
(m/explain schema {:type :x
:hello 1
})
(me/humanize))
:ok)) ;=> ["invalid dispatch value"]
You can use references (strings or qualified keys) in multi body, like with map:
[:multi {:dispatch :type} :domain/user :domain/order]
Ah I see now. Didn’t try qualified keys
there is also an example of lazy registry, could be used too: https://github.com/metosin/malli#lazy-registries
But it’s not possible to leave the multi without the key entries, right?
I want to extend my schema after the first definition
So something like
(def CloudFormation
(m/schema
[:multi {:dispatch :Type, :lazy-refs true}]
{:registry registry}))
I would be easy to ad a new key e.g. :`methods` into multi, that is used for the lookups. Would that work?
Yeah that would be perfect
something like
.. :methods (fn [] @*my-schema)
And then I would change *my-schema
somewhere else, right?I think this would more or less cover what multispec can do
Yep, thanks
@U0FT7SRLP I meant an Issue is enough 🙂
@U055NJ5CC 😅 I actually tried to implement your suggestion by adding a :methods
option. And it works, but after the schema is loaded it doesn't revaluate when the state/multimethod updates. Ill create an issue with an explanation and push what i have so far in a separate draft PR
@U055NJ5CC I created an Issue https://github.com/metosin/malli/issues/786 and the :methods
experiment is in https://github.com/metosin/malli/issues/787