Hi,
I'm sorry to bombard the mailing list but I've been stuck on this one problem for the whole day. Say we have a function `get-ints` with one positional argument, the number of ints the caller wants, and two named arguments `:max` and `:min` like:
;; Ignore that the implementation of the function is incorrect.
(defn get-ints [nr & {:keys [max min] :or {max 10 min 0}}]
(take nr (repeatedly #(int (+ (* (rand) (- max min -1)) min)))))
(get-ints 5) ; => (8 4 10 5 5)
(get-ints 5 :max 100) ; => (78 43 32 66 6)
(get-ints 5 :min 5) ; => (10 5 9 9 9)
(get-ints 5 :min 5 :max 6) ; => (5 5 6 6 5)How does one write a Plumatic Schema for the argument list of `get-ints`, a list of one, three or five values where the first one is always a number and the following items are always pairs of a keyword and an associated value?
I've tried to approach this problem a couple of different ways, but it all comes back to the fact that I can't find a way to concatinate two "pairs" or "sequences" to each other without them defining their own subsequences.
(def kwargs [(schema/optional (schema/pair (schema/enum :max) "max-key" schema/Int "max-val") "arg1")
(schema/optional (schema/pair (schema/enum :min) "min-key" schema/Int "min-val") "arg2")])
(schema/validate kwargs [[:max 10] [:min 5]]) ; => [[:max 10] [:min 5]]
(schema/validate kwargs [[:max 10]]) ; => [[:max 10]]
(schema/validate kwargs [:max 10 :min 5]) ; => Exception
This seems related to an old SO-question on the same subject [0] that has stood unanswered for quite a while, I also posted my question on there earlier today [1].
[0]:
http://stackoverflow.com/questions/29013875/how-to-define-prismatic-schema-for-interleaved-types[1]:
http://stackoverflow.com/questions/43733676/plumatic-schema-for-keyword-arguments