Fork me on GitHub
#malli
<
2021-11-25
>
Johan04:11:54

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 ?

dangercoder09:11:55

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

Johan12:11:41

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 ?

vinurs15:11:50

(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?

Ivan Fedorov16:11:34

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]))

ikitommi18:11:18

Do you have the :merge registered? It's not in the default registry (just yet at least)

Ivan Fedorov11:11:54

@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]})

ikitommi08:11:04

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

❤️ 1