This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-08
Channels
- # announcements (40)
- # babashka (14)
- # babashka-sci-dev (7)
- # beginners (50)
- # calva (8)
- # cider (25)
- # clj-kondo (7)
- # cljdoc (8)
- # cljs-dev (14)
- # clojars (6)
- # clojure (56)
- # clojure-australia (1)
- # clojure-berlin (2)
- # clojure-dev (16)
- # clojure-europe (18)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (7)
- # clojurescript (100)
- # cursive (57)
- # data-science (9)
- # datomic (6)
- # emacs (11)
- # figwheel (2)
- # fulcro (14)
- # helix (2)
- # hyperfiddle (9)
- # introduce-yourself (1)
- # lsp (20)
- # malli (14)
- # meander (34)
- # minecraft (1)
- # missionary (8)
- # off-topic (37)
- # pedestal (4)
- # polylith (18)
- # portal (3)
- # re-frame (5)
- # ring (33)
- # shadow-cljs (32)
- # spacemacs (6)
- # vim (16)
It seems that I can't use recursive schemas in regular expression schemas?
(def selector-schema
(malli/schema
[:schema {:registry {::selector [:and vector? [:+ [:cat keyword? [:? [:ref ::selector]]]]]}}
[:ref ::selector]]))
(malli/validate selector-schema [:foo [:bar]])
; Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:138).
; :malli.core/potentially-recursive-seqex [:ref :user/selector]
Is there another way to specify this? I basically want to specify a vector of keywords, that are optionally followed by a vector that conforms to the same spec...you can’t inline the recursive references (reasoning https://github.com/metosin/malli/blob/master/src/malli/impl/regex.cljc), but you can use them, with explicit :schema
wrapping, e.g.
(def selector-schema
(malli/schema
[:schema {:registry {::selector [:and vector? [:+ [:cat keyword? [:? [:schema [:ref ::selector]]]]]]}}
[:ref ::selector]]))
Thanks a bunch!
This works!
I wonder if we should place a hint to that somewhere in the README. Happy to give it a try and PR
I was about to give up already, would never have guessed to wrap it in [:schema]
> As all these examples show, the “seqex” operators take any non-seqex child schema to mean a sequence of one element that matches that schema. To force that behaviour for a seqex child :schema
can be used:
>
(m/validate
> [:cat [:= :names] [:schema [:* string?]] [:= :nums] [:schema [:* number?]]]
> [:names ["a" "b"] :nums [1 2 3]])
> ; => true
>
> ;; whereas
> (m/validate
> [:cat [:= :names] [:* string?] [:= :nums] [:* number?]]
> [:names "a" "b" :nums 1 2 3])
> ; => true
> Oh man.
Sorry 🙂
Note to self: Always read the whole section