malli

https://github.com/metosin/malli :malli:
ikitommi 2021-03-11T05:14:40.317Z

@l0st3d & everyone else, opinions on :m/default or :malli/default?

[:multi {:dispatch :type}
 ["object" [:map-of :keyword :string]]
 [:m/default :string]]
vs:
[:multi {:dispatch :type}
 ["object" [:map-of :keyword :string]]
 [:malli/default :string]]
… same could be used for extra-keys in maps, e.g. :m/extra vs :malli/extra. Personally fond of the :m.

Ed 2021-03-11T08:37:55.317700Z

That would definitely solve my problem and make my code easier to read ... it get's my vote ... many thanks for the impressively fast feedback.

Ed 2021-03-11T08:41:07.317900Z

Although maybe ::m/default might be better

Ed 2021-03-11T08:41:33.318100Z

Ah ... I see someone has already commented to that effect on the pr 😉

Helins 2021-03-11T10:40:46.318600Z

Hehe, sometimes I dream about creating a sub-community of "Clojurists against too much abbreviation"

Ed 2021-03-11T10:48:59.318800Z

😉 ... I think it's not about abbreviation, but scope ... :m/ is a public namespace that may be being used by an application and may well be a target in that multi dispatch, whereas ::m/ is scoped to malli.core and therefore shouldn't have meaning in your application - so it's fine to use as a default ... I think where clojure pushes back against brevity it tends to be for reasons of applicability in different contexts - which makes it a more generally useful language

2👍
ikitommi 2021-03-11T05:14:50.317100Z

https://github.com/metosin/malli/pull/391

ikitommi 2021-03-11T05:15:18.317500Z

(def valid?
  (m/validator
    [:multi {:dispatch :type}
     ["object" [:map-of :keyword :string]]
     [:m/default :string]]))

(valid? {:type "object", :key "1", :value "100"})
; => true

(valid? "SUCCESS!")
; => true

(valid? :failure)
; => false

Ed 2021-03-11T08:37:55.317700Z

That would definitely solve my problem and make my code easier to read ... it get's my vote ... many thanks for the impressively fast feedback.

Ed 2021-03-11T08:41:07.317900Z

Although maybe ::m/default might be better

Ed 2021-03-11T08:41:33.318100Z

Ah ... I see someone has already commented to that effect on the pr 😉

Helins 2021-03-11T10:40:46.318600Z

Hehe, sometimes I dream about creating a sub-community of "Clojurists against too much abbreviation"

Ed 2021-03-11T10:48:59.318800Z

😉 ... I think it's not about abbreviation, but scope ... :m/ is a public namespace that may be being used by an application and may well be a target in that multi dispatch, whereas ::m/ is scoped to malli.core and therefore shouldn't have meaning in your application - so it's fine to use as a default ... I think where clojure pushes back against brevity it tends to be for reasons of applicability in different contexts - which makes it a more generally useful language

2👍
armed 2021-03-11T14:33:40.319500Z

Hello, how to attach custom error message to seqexp? For example:

(malli.error/humanize
  (malli/explain
   [:map
    [:items
     [:+
      {:error/message "Items must not be empty"}
      [:map [:foo string?
             :bar int?]]]]]
   {:items []}))

armed 2021-03-11T14:34:25.320Z

I get {:items [["unknown error"]]} error

2021-03-11T17:46:54.320900Z

looks like the :error/message is in the wrong place:

(me/humanize
 (m/explain
  [:map
   [:items
    [:+
     [:map {:error/message "Items must not be empty"}
      [:foo string?
       :bar int?]]]]]
  {:items []}));; => {:items [["Items must not be empty"]]}

emccue 2021-03-11T17:59:34.321400Z

How would I represent values like this

emccue 2021-03-11T17:59:58.322Z

:keyword-a
:keyword-b
{:map "with" :some 'shape}

emccue 2021-03-11T18:00:12.322300Z

(in the same schema)

emccue 2021-03-11T18:02:53.322700Z

at least with the online tool, alt doesn't seem to do what I would expect

emccue 2021-03-11T18:03:51.322800Z

ikitommi 2021-03-11T18:34:23.325Z

the http://malli.io is not updated for 0.3.0, so no :alt there yet. PR welcome to update deps

emccue 2021-03-11T18:38:35.325300Z

would alt work in that case?

nilern 2021-03-11T18:43:32.327400Z

:alt is for sequences only

nilern 2021-03-11T18:47:39.329200Z

[:alt [:= :a] [:= :b]] matches [:a] and (:b) but not :a

armed 2021-03-11T18:55:04.331400Z

Thanks, thats interesting. My code works if I replace :+ with :vector

armed 2021-03-11T18:57:55.333800Z

And if I put error inside :map, then all other map validation errors replaced with that one, even ‘missing key’ is becomes ‘items must not be empty’.

emccue 2021-03-11T19:08:31.334800Z

interesting that [:enum :a :b] is different than [:or [:= :a] [:= :b]]

ikitommi 2021-03-11T19:19:29.335300Z

updated http://malli.io, with few sequence samples (args & hiccup)

ikitommi 2021-03-11T19:21:31.336100Z

the Hiccup in JSON Schema looks fishy:

{:$ref "#/definitions/hiccup", :definitions {"hiccup" {}}}

ikitommi 2021-03-11T19:22:13.337Z

but, there are no sequence schemas there, so i guess it’s the best we can do.

ikitommi 2021-03-11T19:23:31.337100Z

different, how?

emccue 2021-03-11T20:06:36.337300Z

like, they are inferred differently