This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-25
Channels
- # announcements (1)
- # asami (3)
- # aws (2)
- # babashka (8)
- # beginners (60)
- # biff (3)
- # calva (45)
- # clj-http (3)
- # clj-kondo (19)
- # clojure (50)
- # clojure-europe (23)
- # clojure-nl (8)
- # clojure-spec (4)
- # clojure-uk (3)
- # clojurescript (32)
- # conjure (3)
- # datomic (7)
- # events (2)
- # fulcro (24)
- # graalvm (3)
- # inf-clojure (3)
- # jackdaw (1)
- # lsp (3)
- # malli (8)
- # missionary (14)
- # off-topic (1)
- # polylith (3)
- # portal (11)
- # rewrite-clj (63)
- # shadow-cljs (21)
- # spacemacs (7)
- # tools-build (6)
- # xtdb (4)
Would malli be a good place to check if value is within a list of ~20k items ? Build a giant [:enum] or custom fn or just not use malli for that ?
I would put that list of 20k items into a set
instead and use clojure.core contains?
function.
If you want to check that through malli you can always create a custom :fn
For example I want to check a postcode, would you just use a malli schema to check if the value is a number and then check if it's part of the country list of postcode ?
(def get-categories-req
[:map {:title "get-categories-req"}
[:categories [:vector {:description "category id"
:default [0 1]
} int? ]]])
hello, i define the malli schema like this, and call
it shows the error
{
"schema": "[:map {:title \"get-categories-req\", :closed true} [:categories [:vector {:description \"category id\", :default [0 1]} int?]]]",
"errors": [
{
"value": "0,1",
"in": [
"categories"
],
"message": "invalid type",
"path": [
"categories"
],
"schema": "[:vector {:description \"category id\", :default [0 1]} int?]",
"type": "malli.core/invalid-type"
}
],
"value": {
"categories": "0,1"
},
"type": "reitit.coercion/request-coercion",
"coercion": "malli",
"in": [
"request",
"query-params"
],
"humanized": {
"categories": [
"invalid type"
]
}
}
how can i make malli parse this?Can malli’s [:merge]
work inside a registry?
this fails for me
(def registry:shopify
{:e.shopify/address1
[:map [:first_name string?]]
:e.shopify/address2
[:map [:city string?]]
:e.shopify/address-full
[:merge
:e.shopify/address1
:e.shopify/address2]})
(def schema:address-full
(m/schema
[:schema {:registry registry:shopify}
:e.shopify/address-full]))
Do you have the :merge
registered? It's not in the default registry (just yet at least)
@U055NJ5CC How would I do this? This doesn’t work at least 🙂
(def registry:shopify--
{:merge mu/merge
:e.shopify/address1
[:map [:first_name string?]]
:e.shopify/address2
[:map [:city string?]]
:e.shopify/address-full
[:merge
:e.shopify/address1
:e.shopify/address2]})
maps do not have order, any of the entries using merge might get resolved before the :merge
. I’ll change how the default registry works, so this would be easier. Before that:
1. use mu/merge
instead of :merge
2. swap the default registry with one that has the :merge
3. use composite registry, e.g. (mr/composite-registry {:merge mu/merge} {:e.shopify/address1 …})
, in case the :merge
should be registered before the actual schemas