Simplest would be to do something like this: (def Schema (s/cond-pre s/Int (s/constrained clojure.lang.Reduced #(integer? @%))))
although this doesn't allow you to use the schema in both places. The right way would be to make a new `Reduced` schema: (defrecord Reduced [schema] schema.core/Schema (spec [this] (schema.spec.collection/collection-spec (schema.spec.core/precondition this #(instance? clojure.lang.Reduced %) #(list 'instance? clojure.lang.Reduced %)) reduced [(schema.spec.collection/one-element true schema (fn [item-fn r] (item-fn @r) nil))] (clojure.core/fn [_ xs _] (reduced (first xs))))) (explain [this] (list 'reduced-val (schema.core/explain schema)))) (defn reduced-val [schema] (Reduced. schema)) (defn possibly-reduced [schema] (s/cond-pre (reduced-val schema) schema)) (s/validate [(possibly-reduced s/Int)] [1 (reduced 1)]) Best, Jason On Friday, April 1, 2016 at 6:17:48 AM UTC+5:45, JvJ wrote: > > > When using functions with schema type signatures for reduce, I run into > output schema errors whenever I try to short-circuit the reducing operation > by wrapping the return value in reduced. How can I modify the type > signature so that it accepts output values of types A and (reduced A)? > -- 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 new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.