Fork me on GitHub
#clojure-spec
<
2018-01-02
>
pablore15:01:25

How would you spec this function?

(defn reducer
  ([] {})
  ([state action]
    (...)))
Where state and action are specced

taylor15:01:19

(defn such-arity
  ([] "nullary")
  ([one] "unary")
  ([one two & many] "one two many"))

(s/fdef such-arity
        :args (s/alt :nullary (s/cat)
                     :unary (s/cat :one any?)
                     :variadic (s/cat :one any?
                                      :two any?
                                      :many (s/* any?))))

pablore15:01:10

I thought that could solve my validation problem with my function, but it still failing :c

pablore15:01:26

Couldn't satisfy such-that predicate after 100 tries. {}

taylor16:01:04

that could be due to one of your specs using an s/and and not being able to generate something that conforms to the whole spec

taylor16:01:45

(s/def ::foo-map (s/and map? #(:foo %)))
(gen/sample (s/gen ::foo-map))
ExceptionInfo Couldn't satisfy such-that predicate after 100 tries.  clojure.core/ex-info (core.clj:4739)

taylor16:01:52

for example ☝️ that s/and is generating based off that first map? predicate, but the generator is unlikely to produce a map with :foo and so it gives up after so many tries

pablore16:01:00

Cannot fix it for now. Will put it on hold until errors are more specific

pablore16:01:13

thanks anyway for the info