Fork me on GitHub
#clojure-spec
<
2018-02-05
>
dominicm09:02:07

Is there a s/cat function which doesn't create a map? I essentially want a regex op which will consume exactly 2 predicates.

dominicm13:02:15

@U064X3EF3 That isn't a regex op, so it doesn't work for this:

(s/conform
  (s/cat
    :foo int?
    :bar (s/tuple int? int?)
    :baz int?)
  [1 2 3 4])

dominicm13:02:46

(s/conform
  (s/cat
    :foo int?
    :bar (s/cat :a int? :b int?)
    :baz int?)
  [1 2 3 4])
;; =>
;; {:foo 1, :bar {:a 2, :b 3}, :baz 4}
with the s/cat regex op

Alex Miller (Clojure team)13:02:22

s/+ then s/& with a size constraint?

dominicm13:02:34

@U064X3EF3 This works!

(s/conform
  (s/cat
    :foo int?
    :bar (s/& (s/+ int?) #(= 2 (count %)))
    :baz int?)
  [1 2 3 4])
Rather cool.

dominicm13:02:17

I didn't really understand s/& when I read the docstring.

Alex Miller (Clojure team)13:02:20

it’s like s/and but as a regex op

dominicm14:02:09

That's a good description. I prefer that

dominicm09:02:36

Maybe my mistake is using something positional where I should be using a map

mattford10:02:52

do you have to conform it?

mattford10:02:50

I've instrumented and stubbed out a function that thanks to the magic of spec can now generate results. The result is generated from a multispec though, is there a way of limiting a multispec to one of the methods [so I can only return certain types of results]?

acron10:02:51

@mattford add a predicate check for the dispatch type

acron10:02:45

(s/cat :foo (s/and ::my/thing is-correct-thing?))

acron10:02:03

where ::my/thing is your multispec

acron10:02:27

this has worked relatively successfully for me

acron10:02:21

What would cause clojure.spec.test.alpha/spec-checking-fn/conform! to be applied to a function that has *not* been instrumented? :thinking_face:

mattford10:02:45

Feels a bit circular having a mutlispec generate many cases only then to filter it again on the same logic each defmethod has.

mattford11:02:08

works though...

acron11:02:15

Well, the real question could be why do we want just one result type generating?

mattford11:02:28

I instrumented my general get-event handler but I'm only interested in testing "visualisation" events in the next part of the tests..

tcoupland16:02:32

@mattford check out the :gen option of instrument