Fork me on GitHub
#clojure-spec
<
2023-10-17
>
Ho0man16:10:58

Hi everyone, I wanna spec sth like this :

[[:__      :TXC    :BTC    :ALT    :PAXG   ]
 [:TT1     0M      0M      0M       0M     ]
 [:TT2     0M      0M      0M       0M     ]
 [:TT3     0M      0M      0M       0M     ]
 [:TT4     0M      0M      0M       0M     ]
 [:Others  0M      0M      0M       0M     ]
 ]
but the following spec won't work :
(spec/def ::X-Header-Row     (spec/cat :dont-care #{:__} :exposure-id-s (spec/+ ::Exposure-ID)))
(spec/def ::X-Row            (spec/cat :g-id ::Group-ID :weights (spec/+ decimal?)))
(spec/def ::X                (spec/cat :header ::X-Header-Row  :rows (spec/+ ::X-Row)))
What is it that I'm not getting about how spec/cat works and how can I spec that table ? Thanks a lot in advance

Alex Miller (Clojure team)16:10:20

won't work .... because?

Alex Miller (Clojure team)17:10:43

regex ops combine to spec one collection, so you need to do something to separate the outer collection and the inner collection "levels"

Alex Miller (Clojure team)17:10:26

probably the shortest path to that is to wrap s/spec around the ::X-Row cat

Ho0man11:10:39

Thanks a lot, Alex