This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-06
Channels
- # announcements (1)
- # aws (36)
- # babashka (105)
- # beginners (53)
- # calva (27)
- # cider (5)
- # clj-kondo (10)
- # clojure (232)
- # clojure-europe (4)
- # clojure-italy (6)
- # clojure-losangeles (9)
- # clojure-nl (3)
- # clojure-sanfrancisco (3)
- # clojure-uk (124)
- # clojured (3)
- # clojurescript (57)
- # clojutre (1)
- # core-async (9)
- # core-logic (1)
- # cryogen (23)
- # cursive (35)
- # datomic (12)
- # duct (4)
- # events (1)
- # figwheel-main (3)
- # fulcro (9)
- # graalvm (31)
- # jobs (1)
- # jobs-discuss (85)
- # kaocha (11)
- # leiningen (11)
- # luminus (19)
- # malli (47)
- # meander (12)
- # nrepl (8)
- # off-topic (32)
- # pathom (4)
- # pedestal (2)
- # reagent (7)
- # ring-swagger (1)
- # schema (3)
- # sql (5)
- # tools-deps (114)
- # vim (17)
- # xtdb (12)
Just pasted a huge JSON sequence into https://malli.io and got a nice, readable schema out, with optional values, sequences and everything in place. What a pleasure! Thanks! 🙏
Hi! I'm trying to mu/merge two specs [:map ...] and [:multi ... ]. Why I always have only one of them in a result? Is there any examples?
@mike1452 they are of different types and the last one wins (like with clojure.core/merge
)
@ikitommi thanx.
but, the merge is far from perfect, not sure what happens if one merges two multis for example.
i would assume that they get merged together, but not sure if the impl has a special condition just for :map
(should be for MapSchema
s, which both multi and map are)
… with that change, could actually merge those togerher. not sure if that’s a good idea thou :thinking_face:
another question: when I generate multi spec, why I have random values in dispatch type instead of those values that in multi spec?
(def mumap
[:multi {:dispatch :db/shared-channel}
["folder" [:map [:db/shared-channel string?] [:db/shared-channel-folder string?]]]
["web" [:map [:db/shared-channel string?] [:db/shared-channel-url string?]]]])
instead of "folder" and "web" in shared channel i have random values. I expect only these two values
try:
[:map [:db/shared-channel [:= "folder"]] [:db/shared-channel-folder string?]]
as the dispatch can be anything, it’s non-trivial to use the branch name in a generator automatically
I did multi spec
(def mumap
[:multi {:dispatch :db/shared-channel}
["folder" [:map [:db/shared-channel [:= "folder"]] [:db/shared-channel-folder string?]
[:db/type [:and string? [:fn {:error/message "should not be empty string"} not-empty-string?]]]
[:h2/filename {:default "./boxdb"} string?]
[:h2/user {:default "sa"} string?]]]
["web" [:map [:db/shared-channel [:= "web"]] [:db/shared-channel-url string?]
[:db/type [:and string? [:fn {:error/message "should not be empty string"} not-empty-string?]]]
[:h2/filename {:default "./boxdb"} string?]
[:h2/user {:default "sa"} string?]]]])
Question: how to avoid duplication of first half? (merge is not work like in spec1)
I need something like:
[:map
[:db/type [:and string? [:fn {:error/message "should not be empty string"} not-empty-string?]]]
[:h2/filename {:default "./boxdb"} string?]
[:h2/user {:default "sa"} string?]
[:multi {:dispatch :db/shared-channel}
["folder" [:map [:db/shared-channel [:= "folder"]] [:db/shared-channel-folder string?]]]
["web" [:map [:db/shared-channel [:= "web"]] [:db/shared-channel-web string?]]]]]
many ways to do that, one would be to create a basemap, and merge that in all branches:
(def BaseMap
[:map
[:db/type [:and string? [:fn {:error/message "should not be empty string"} not-empty-string?]]]
[:h2/filename {:default "./boxdb"} string?]
[:h2/user {:default "sa"} string?]])
(def Multi
[:multi {:dispatch :db/shared-channel}
["folder" (mu/merge BaseMap [:map [:db/shared-channel [:= "folder"]] [:db/shared-channel-folder string?]])]
["web" (mu/merge BaseMap [:map [:db/shared-channel [:= "web"]] [:db/shared-channel-web string?]]])]])
the oldest non-resolved issue in malli: https://github.com/metosin/malli/issues/14
https://malli.io seems to fail to infer the schema of values containing instants. Example value:
{:some-date #inst "2020-02-02"}
Is this expected behavior?I would not expect that. from a repl:
(require '[malli.provider :as mp])
(mp/provide [{:some-date #inst "2020-02-02"}])
; => [:map [:some-date inst?]]
@ikitommi for https://github.com/metosin/malli/issues/180, do we want to also add support for :+ :* :?
and some other operators? in the :cat
driven sequence?
I hope to start this issue if I have some time this weekend.
(if I have time)
Could you push this to a branch ?
actually, that’s about it. here are the codes I was playing with:
(require '[net.cgrand.seqexp :as se])
(se/exec
(se/cat
(se/as :x int?)
(se/as :y int?)
(se/as :rest2 (se/* string?)))
[1 2 "kikka" "kukka"])
; {:rest (), :match (1 2 "kikka" "kukka"), :x (1), :y (2), :rest2 ("kikka" "kukka")}
[:cat
[:x int?]
[:y int?]
[:rest [:* string?]]]
(se/exec-tree
(se/cat
(se/*
(se/as [:opts]
(se/cat
(se/as [:opts :x] string?)
(se/| (se/as [:opts :s] string?) (se/as [:opts :b] boolean?))))))
["-server" "foo" "-verbose" true "-user" "joe"])
(se/exec
(se/cat
(se/as :x (se/repeat 1 int?))
(se/as :y int?)
(se/as :restz (se/* string?)))
[1 2 "kikka" "kukka"])
; {:rest (), :match (1 2 "kikka" "kukka"), :x (1), :y (2)}
(se/*
(se/as [:sections]
(se/cat :h1
(se/as [:sections :ps]
(se/+ :p)))))
thank you
just updated https://github.com/cgrand/seqexp/issues/11, which is about using seqexp here
I will start by writing tests
.. then the implementation to make them pass
Using malli.provider/provide
does the trick! Thanks.
I was surprised by what happened when I forgot to provide a sequence:
(mp/provide {:some-date #inst "2020-02-02"})
;; => [:vector some?]
com.github.metosin/malli {:git/url ""
:sha "9db4ff998b641d4a0cff4eb6d772fd0cb5d3b56c"}
Maps turn into sequences in Clojure, so it’s a sequence of a vector of keyword?
and inst?
, which both are some?
(seq {:some-date #inst "2020-02-02"})
;; => ([:some-date #inst"2020-02-02T00:00:00.000-00:00"])
last time I checked, the regexs where implemented using regular hashmaps in spec, would need at least some wrapping, don’t want to reserve maps for any one schema (family) type.