Re: using clojure spec for dispatching on different map structures

2017-09-13 Thread Didier
I'm not following 100%. But s/or of specs will comform to the first valid spec it encounters. It can be used for duck typing, aka, strutural types. So given you have many maps, each can be a spec. Then you can create a spec which is one of these shapes of maps. Pass any map to the or spec, and i

Re: using clojure spec for dispatching on different map structures

2017-09-13 Thread Alex Miller
I don't see any benefit of using a subset of spec to do this - why not just use normal Clojure code on sets of keys? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from ne

Re: using clojure spec for dispatching on different map structures

2017-09-13 Thread Brent Millare
Yeah, that's what I thought. I guess I'm using it in a way that's not standard practice. Luckily it's not a bottleneck in my case. Has there been discussion about a "shortable" version of s/keys which just checks for key existence and doesn't recursively validate the corresponding values? I su

Re: using clojure spec for dispatching on different map structures

2017-09-13 Thread Alex Miller
Seems pretty slow to dispatch on a linear series of spec validations, but I don't see any reason it wouldn't work. On Wednesday, September 13, 2017 at 3:47:40 PM UTC-5, Brent Millare wrote: > > The example for multi-spec provided in the spec guide assumes a key that > denotes a "type". (This key

Re: using clojure spec for dispatching on different map structures

2017-09-13 Thread Brent Millare
The example for multi-spec provided in the spec guide assumes a key that denotes a "type". (This key is used as the dispatch fn). In my situation, I'm assuming I don't have control over what maps are generated. In other words, I explicitly do not want to have to encode types into the input map.

Re: using clojure spec for dispatching on different map structures

2017-09-13 Thread Alex Miller
You might want to look at s/multi-spec which lets you create a variable open spec based on a multimethod, which would in this case be based on key availability. On Wednesday, September 13, 2017 at 11:54:31 AM UTC-5, Brent Millare wrote: > > I have several maps with different combinations of key

using clojure spec for dispatching on different map structures

2017-09-13 Thread Brent Millare
I have several maps with different combinations of keys for each map. I want to process each map but do different work depending on the set of keys available, basically dispatch on key availability. I thought clojure.spec might be a good fit for doing the classification step. So for each key, I