malli

erre lin 2025-08-17T16:34:45.595659Z

When it comes to the idea of “several some things (same type/schema)”, it seems I can have (at least) two options:

(def Deck
  [:vector {:min 1} Card])

;; or
(def Deck2
 [:repeat {:min 1} Card])
I usually prefer the vector approach, but I’m wondering when the repeat pattern works better? What would you suggest? Thanks in advance

valtteri 2025-08-17T18:34:59.236649Z

For simple cases where you expect exactly one type of elements in the collection, I recommend using :vector (if you want/need the collection to be a vector) or :sequential which is a bit more relaxed and allows the collection type to be any sequential collection (e.g. list or vector). :repeat is part of the "seqexp" machinery, that's designed to support more complex cases, where you need to express schemas such as "the first two items should be numbers followed by 3-10 strings". :repeat is typically used in combination with other seqexp schemas to express schemas like this. Seqexp schemas provide more expression power with a performance cost compared to simpler sequence or type specific schemas.

👏 1
erre lin 2025-08-18T06:08:04.359539Z

Thanks valtteri. The explanation makes great sense to me. I hope such suggestions (design purposes) could be made more apparent in the relevant doc sections.