Fork me on GitHub
#clojure-spec
<
2018-05-12
>
dottedmag12:05:18

I have a spec:

(s/def ::statement (s/cat ::header ::header
                          ::delimiter ::delimiter
                          ::txs-header ::txs-header
                          ::txs ::txs))
-- is it how it is supposed to look like, or am I missing some shorthand?

dottedmag12:05:23

::header, ::delimiter etc are declared using s/cat themselves, so I suppose s/tuple can't be used here.

dottedmag12:05:43

Maybe there is a simpler way to spec this data format? The input is a CSV file parsed into a vector of vectors. Header is a number of lines, more-or-less fixed, but some are optional and may be omitted. Delimiter is a single fixed line. Txs headers is another set of more-or-less fixed lines, and txs is the rest of the document.

Alex Miller (Clojure team)13:05:45

s/tuple might be better

Alex Miller (Clojure team)13:05:48

For vector of fixed position fields

dottedmag13:05:39

Too bad they are mostly, but not completely, fixed. Banks are, well, banks.

ghadi13:05:31

I would turn the vec of vecs into a vec of maps, then spec with s/keys

4
dottedmag13:05:22

Parsing individual lines is not so bad — they can be handled by s/tuple. Parsing the sequence of lines is worse.

dottedmag13:05:46

I'll leave it with s/cat for now.