malli icon indicating copy to clipboard operation
malli copied to clipboard

malli.core/schema doesn't work for lists

Open bsless opened this issue 1 year ago • 1 comments

While schema literals will most likely be written in vector forms, when building schemas programatically there's a chance the schema won't be a vector

Minimal case: (malli.core/schema (list :int)) vs (malli.core/schema (vector :int))

bsless avatar Sep 07 '23 05:09 bsless

That is true. But Map-syntax is better anyway for programmatically creating schemas?

Bit related:

Had an idea to misuse the list + symbol syntax as a "malli-lite2" syntax, but buried the idea as too-many-syntaxes. this:

[:map
 [:id :int]
 [:size [:maybe [:set [:enum "s" "m" "l"]]]]]

... could be represented as:

'(map
  [:id :int]
  [:size (maybe (set (enum "s" "m" "l")))])

... with auto-converting list+symbol into vector+keyword.

But I think it's better to have functional explicit dsl instead:

(require '[malli.dsl :as md])

(md/map
 :id :int
 :size (md/maybe (md/set (md/enum "s" "m" "l"))))

... which allows proper static analysis by tools like cursive & clj-kondo on arguments.

ikitommi avatar Sep 10 '23 11:09 ikitommi