Fork me on GitHub

I’m trying to use regex ops and running into some problems. I have two data structures naturally represented by a regex, the main one is of the shape: a*c, in my map data structure in order to get the item at that location, the get-in path is something like (ab)*c — it seems that the problem is that nested regex operators “merge”; so now for a fn that takes a*c and returns (ab)*c, I can’t specify its :args as (s/cat :a ::a) — does that make sense?


Looks like that’s intentional; found it in the guide 🙂 > When regex ops are combined, they describe a single sequence. If you need to spec a nested sequential collection, you must use an explicit call to spec to start a new nested regex context. For example to describe a sequence like [:names ["a" "b"] :nums [1 2 3]], you need nested regular expressions to describe the inner sequential data:


Makes sense — you’d want to be able to parse both, and break them out 🙂


Hi, how do I spec functions with optional arguments?


sveri: usually you use regex ops to describe the args as they would be given to apply


so .e.g you can use spec/?


How would you spec 2 arguments where one arg's validity depends on the other arg.


For example: (fn [i-am-a-map i-am-a-key-in-the-map] ...)


potetm: you can use s/and


@gfredericks perfect; just figured that out 🙂