idleherb
idleherb

Reputation: 1101

How to spec a vector of custom spec'ed maps

I have a spec for a custom map named ::cell, let's say

(s/def ::attr-1 int?)
(s/def ::attr-2 int?)
(s/def ::cell :req-un [::attr-1 ::attr-2])

Now I want another spec ::grid for a custom vector that consists of only these ::cell maps. As an example, a grid might look like this:

(let grid [{:attr-1 11, :attr-2 12} {:attr-1 21 :attr-2 22}])

Is it possible to create a spec for this requirement using the specification of ::cell?

(s/def ::grid ???)

Upvotes: 0

Views: 165

Answers (1)

Lee
Lee

Reputation: 144206

You can use tuple:

(s/def ::grid (s/tuple ::cell ::cell ::cell))

or coll-of specifying the kind and count:

(s/coll-of ::cell :kind vector? :count 3)

Upvotes: 3

Related Questions