Fork me on GitHub
Yehonathan Sharvit08:06:56

What's the rationale behind the fact that a set is considered as :sequential ? For instance

(validate [:sequential string?] #{"aa"}) ;; false


it’s following the clojure way:

{:sequential (m/-collection-schema {:type :sequential, :pred sequential?})}

(sequential? #{}) ; => false


you should be able create custom collections types easily that access both sequentials and sets.

Yehonathan Sharvit08:06:03

@ikitommi Could you share a pointer to the documentation about custom collection types?

Yehonathan Sharvit10:06:33

How it would look like to create a custom :sequential-or-set predicate? And where would i put its definition?


1. def a Var and use it instead of the type (keword), like with Reagent 2. add it to a registry, see README for alternatives


(def SequentialOrSet (m/-col...))

(m/validate [SequentialOrSet :int] [1])


@viebel sequential means: it has a defined order. sets are not ordered, similar to maps, although you can create sequences out of them

Yehonathan Sharvit14:06:05

Yeah. It makes sense. But still surprising.

Yehonathan Sharvit14:06:41

I think we need a name and a predicate for a bunch of things that could be either in a set or in a sequence

Yehonathan Sharvit14:06:30

My use case is a function that receives a bunch of ids and return the entities whose id is contained in the bunch


you could always say [:or [:sequential :int] [:set :int]].


or, one could always transform the values always to sets/vectors.


coll? works as well, if you don't mind using predicates directly


(coll? {}) ;=> true


coercion is always an option:

 [:set :int]
 [1 2 3]
; => #{1 2 3}


Any recommendations on how to approach extracting out a registry from a schema? For example:

  [::id int]
  [:name string?]
  [::country {:optional true} string?]]


{::id int?
 ::country string?}

and as a nice to have, the schema simplified to use the new registry:

  [:name string?]
  [::country {:optional true}]]
Use cases: • Simplify large schemas • Finding differences in semantics • Refactoring multiple schemas to use a shared registry